Simple image host.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.node.js 376B

1234567891011121314151617
  1. var fs = require("fs");
  2. module.exports = function(ctx) {
  3. var id = ctx.query.replace(/\..*/, "");
  4. if (!id)
  5. return ctx.end(ctx.view("404"));
  6. var readStream = fs.createReadStream(ctx.conf.dir.imgs+"/"+id);
  7. readStream.pipe(ctx.res);
  8. readStream.on("error", function(err){
  9. if (err.code == "ENOENT")
  10. ctx.end(ctx.view("404"));
  11. else
  12. ctx.end(err.toString());
  13. });
  14. }