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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 name, date_created, id "+
  7. "FROM collections "+
  8. "WHERE user_id = $1",
  9. [id],
  10. function(err, res) { a("collections", res, err) }
  11. );
  12. ctx.db.query(
  13. "SELECT username "+
  14. "FROM users "+
  15. "WHERE id = $1",
  16. [id],
  17. function(err, res) { a("users", res, err) }
  18. );
  19. var a = ctx.async(2, function(err, res) {
  20. if (err)
  21. return ctx.fail(err);
  22. if (!res.collections || !res.users)
  23. return ctx.err404();
  24. var user = res.users.rows[0];
  25. if (!user)
  26. return ctx.err404();
  27. var collections = "";
  28. res.collections.rows.forEach(function(row) {
  29. var d = new Date(row.date_created);
  30. collections += ctx.template("collection", {
  31. name: row.name,
  32. date_created: d.toString(),
  33. id: row.id,
  34. own_profile: (ctx.session.userId === id)
  35. });
  36. });
  37. ctx.end(ctx.view("profile", {
  38. username: user.username,
  39. collections: collections
  40. }));
  41. });
  42. }