diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-10 17:25:32 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-10 17:25:32 +0100 |
| commit | 3cc9ff370a5e3f5bf321dc56963ae3bc73e75284 (patch) | |
| tree | 194bcafac19e2cc1a77aaab7303d68aafdbbe312 /bucky/app/bucky.js | |
| parent | d9b9383118302aff6d73856175d7362d8b1463c5 (diff) | |
posting new threads and comments working
Diffstat (limited to 'bucky/app/bucky.js')
| -rw-r--r-- | bucky/app/bucky.js | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 5198400..2b07f03 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -87,7 +87,7 @@ var bucky = module.exports = { private: false, color: req.body.color, viewed: 0, - revision: 'a', + revision: 0, } db.createThread(data).then(function(thread){ res.thread = thread @@ -221,16 +221,33 @@ var bucky = module.exports = { res.json({ error: "no files" }) return } - var data = { - thread: res.thread.get('id'), - parent_id: req.body.parent_id || -1, - username: req.user.get('username'), - date: util.now(), - comment: req.body.comment, - } - db.createComment(data).then(function(comment){ - res.comment = comment - next() + var thread_id = res.thread.get('id') + var dirname = '/bucky/data/' + thread_id + '/' + var promises = req.files.map((file) => { + return new Promise( (resolve, reject) => { + upload.put({ + file: file, + preserveFilename: true, + dirname: dirname, + unacceptable: function(err){ + reject(err) + }, + success: function(url){ + var data = { + thread: res.thread.get('id'), + username: req.user.get('username'), + filename: file.originalname, + date: util.now(), + size: file.size, + private: false, + storage: 'i.asdf.us', + } + db.createFile(data).then(function(file){ + resolve(file) + }).catch( (err) => reject(err) ) + } + }) + }) }) }, |
