Simple image host.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.node.js 552B

1234567891011121314151617181920212223242526272829
  1. var fs = require("fs");
  2. module.exports = function(ctx) {
  3. var parts = ctx.query.split(".");
  4. var collection = parseInt(parts[0]);
  5. var id = parseInt(parts[1]);
  6. if (!id || !collection)
  7. return ctx.err404();
  8. ctx.res.setHeader(
  9. "Cache-Control",
  10. "public, max-age="+ctx.conf.cache_max_age_images
  11. );
  12. var readStream = fs.createReadStream(
  13. ctx.conf.dir.imgs+"/"+
  14. collection+"/"+
  15. id
  16. );
  17. readStream.pipe(ctx.res);
  18. readStream.on("error", function(err){
  19. if (err.code === "ENOENT")
  20. ctx.err404();
  21. else
  22. ctx.end(err.toString());
  23. });
  24. }