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.

collection_create.node.js 581B

12345678910111213141516171819202122232425262728293031323334
  1. var fs = require("fs");
  2. module.exports = function(ctx) {
  3. ctx.getPostData(function(err, data) {
  4. if (err)
  5. return ctx.fail(err);
  6. ctx.db.query(
  7. "INSERT INTO collections (name, user_id) "+
  8. "VALUES ($1, $2) "+
  9. "RETURNING id",
  10. [data.name, ctx.session.userId],
  11. queryCallback
  12. );
  13. });
  14. function queryCallback(err, res) {
  15. if (err)
  16. return ctx.fail(err);
  17. var id = res.rows[0].id;
  18. fs.mkdir(ctx.conf.dir.imgs+"/"+id, function(err) {
  19. if (err)
  20. return ctx.fail(err);
  21. ctx.session.lastCollectionId = id;
  22. ctx.succeed({
  23. id: id
  24. });
  25. });
  26. }
  27. }