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

12345678910111213141516171819202122232425262728293031323334353637
  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. collection: id,
  22. id: row.id,
  23. extension: row.extension,
  24. description: row.description
  25. });
  26. });
  27. ctx.end(ctx.view("view", {
  28. images: images
  29. }));
  30. }
  31. }