diff options
Diffstat (limited to 'bucky/util/federate.js')
| -rw-r--r-- | bucky/util/federate.js | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/bucky/util/federate.js b/bucky/util/federate.js index 95c61c5..472c32e 100644 --- a/bucky/util/federate.js +++ b/bucky/util/federate.js @@ -1,5 +1,5 @@ var fetch = require('node-fetch') -const readFile = require('fs-readfile-promise') +const fs = require('fs') var db = require('../db') var upload = require('../util/upload') var mime = require('mime-types') @@ -60,8 +60,9 @@ module.exports = { return db.getFilesForThread(req.params.id) }).then(files => { var promises = files.map(file => { + copyFileToS3(file, thread_id) file.set('thread', thread_id) - storeFile(file) + file.set('storage', 'i.asdf.us') return send("file", file) }) return promises @@ -83,14 +84,17 @@ module.exports = { 'Accept': 'application/json', }, }).then((res) => {return res.json()}) + then((json) => console.log(json)) } - function storeFile(file){ + function copyFileToS3(file, thread_id){ // since for now we are essentially backing up local files, // upload them directly to s3 - const bucky_fn = file.get('thread') + '/' + file.get('filename') - readFile('public/data/' + bucky_fn) - .then(buffer => { - const remote_path = '/bucky/data/' + bucky_fn + const src_fn = file.get('thread') + '/' + file.get('filename') + const dst_fn = thread_id + '/' + file.get('filename') + fs.readFile('/Users/user/projects/bucky3/public/data/' + src_fn, (err, buffer) => { + if (err) return console.log(err) + const remote_path = '/bucky/data/' + dst_fn + console.log(mime.lookup(file.get('filename'))) upload.client().putBuffer(buffer, remote_path, { 'Content-Length': buffer.length, 'Content-Type': mime.lookup(file.get('filename')), @@ -111,9 +115,6 @@ module.exports = { console.error(err) s3res && s3res.resume && s3res.resume() }) - }).catch(e => { - console.error(e) - }) } } |
