summaryrefslogtreecommitdiff
path: root/bucky
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-15 10:03:16 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-15 10:03:16 +0100
commitca1b3565ed87e04ee18514ce04f30366bfc76fe6 (patch)
treeda75ad346eca3bf7994e0abdf00a0a26cc727d98 /bucky
parent18403daf12e9ec1553f6b39a609374bd39fd16d5 (diff)
fixing federate function
Diffstat (limited to 'bucky')
-rw-r--r--bucky/util/federate.js21
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)
-
})
}
}