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 608B

123456789101112131415161718192021222324252627282930313233
  1. module.exports = function(ctx) {
  2. var id = parseInt(ctx.req.url.split("?")[1]);
  3. if (isNaN(id))
  4. return ctx.end(ctx.view("404"));
  5. ctx.db.query(
  6. "SELECT id, name, description, extension "+
  7. "FROM images "+
  8. "WHERE collection_id = $1",
  9. [id],
  10. queryCallback
  11. );
  12. function queryCallback(err, res) {
  13. if (err)
  14. return ctx.fail(err);
  15. var images = "";
  16. res.rows.forEach(function(row) {
  17. images += ctx.template("image", {
  18. title: row.name,
  19. id: row.id,
  20. extension: row.extension,
  21. description: row.description
  22. });
  23. });
  24. ctx.end(ctx.view("view", {
  25. images: images
  26. }));
  27. }
  28. }