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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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, 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, err) }
  16. );
  17. var a = ctx.async(2, function(err, res) {
  18. if (err)
  19. return ctx.fail(err);
  20. if (!res.collections || !res.users)
  21. return ctx.end(ctx.view("404"));
  22. var user = res.users.rows[0];
  23. if (!user)
  24. return ctx.end(ctx.view("404"));
  25. var collections = "";
  26. res.collections.rows.forEach(function(row) {
  27. var d = new Date(row.date_created);
  28. collections += ctx.template("collection", {
  29. name: row.name,
  30. date_created: d.toString(),
  31. id: row.id
  32. });
  33. });
  34. ctx.end(ctx.view("profile", {
  35. username: user.username,
  36. collections: collections
  37. }));
  38. });
  39. }