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

123456789101112131415161718192021222324252627282930313233343536
  1. module.exports = function(ctx) {
  2. var id = parseInt(ctx.query);
  3. if (isNaN(id))
  4. return ctx.err404();
  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. if (!res.rows[0])
  16. return ctx.err404();
  17. var images = "";
  18. res.rows.forEach(function(row) {
  19. images += ctx.template("image", {
  20. title: row.name,
  21. id: row.id,
  22. extension: row.extension,
  23. description: row.description
  24. });
  25. });
  26. ctx.end(ctx.view("view", {
  27. images: images
  28. }));
  29. }
  30. }