diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-01-11 13:55:55 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-01-11 13:55:55 +0100 |
| commit | b3ba48a22ce966e62cfad1671e4ee6f4357bb69f (patch) | |
| tree | 4c670b51c4f43ebf6f857b5999c2bc0f3f0e807c /bucky/db | |
| parent | 2e9e542bfb81c3aff407801e3ae3f08eee0fb3d9 (diff) | |
move file api, debug flag on url to show ids
Diffstat (limited to 'bucky/db')
| -rw-r--r-- | bucky/db/index.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/bucky/db/index.js b/bucky/db/index.js index b10e3d8..350f2a4 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -152,6 +152,27 @@ db.createFile = function(data){ } db.destroyFile = function(id){ } +db.moveFile = function(file, thread_id){ + var s3client = upload.client() + var srcPath = '/bucky/data/' + file.get('thread') + '/' + file.get('filename') + var destPath = '/bucky/data/' + thread_id + '/' + file.get('filename') + var copyPromise = new Promise((resolve, reject) => { + s3client.copy(srcPath, destPath).on('response', function(res){ + s3client.deleteFile(srcPath, function(err, res){ + if (err) { + return reject(err) + } + file.set('thread', thread_id) + file.save().then(() => { + resolve() + }).catch(err => { + reject(err) + }) + }) + }).end() + }) + return copyPromise +} db.destroyFiles = function(files){ var s3client = upload.client() var rmPromises = files.map((file) => { |
