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

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. module.exports = function(ctx) {
  2. var id = ctx.query;
  3. ctx.db.query(
  4. "SELECT name, date_created, id "+
  5. "FROM collections "+
  6. "WHERE user_id = $1",
  7. [id],
  8. function(err, res) { a("collections", res.rows, err) }
  9. );
  10. ctx.db.query(
  11. "SELECT username "+
  12. "FROM users "+
  13. "WHERE id = $1",
  14. [id],
  15. function(err, res) { a("users", res.rows, err) }
  16. );
  17. var a = ctx.async(2, function(err, res) {
  18. if (err)
  19. return ctx.fail(err);
  20. var user = res.users[0];
  21. if (!user)
  22. return ctx.end(ctx.view("404"));
  23. var collections = "";
  24. res.collections.forEach(function(row) {
  25. var d = new Date(row.date_created);
  26. collections += ctx.template("collection", {
  27. name: row.name,
  28. date_created: d.toString(),
  29. id: row.id
  30. });
  31. });
  32. ctx.end(ctx.view("profile", {
  33. username: user.username,
  34. collections: collections
  35. }));
  36. });
  37. }