diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-10 18:30:55 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-10 18:30:55 +0200 |
| commit | 7ad86f6dbb65941f9c7aa49a1938e1a0a5bb7d50 (patch) | |
| tree | 0fc41ed53461e62fa1f8d4dbf7ae7ad287eac544 /bucky | |
| parent | 76d54003f9db7eaa4a03e612e76626c73668ce9d (diff) | |
dont hardcode s3 path
Diffstat (limited to 'bucky')
| -rw-r--r-- | bucky/app/bucky.js | 4 | ||||
| -rw-r--r-- | bucky/db/index.js | 6 | ||||
| -rw-r--r-- | bucky/util/federate.js | 4 | ||||
| -rw-r--r-- | bucky/util/middleware.js | 10 |
4 files changed, 17 insertions, 7 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 81b71a4..f8ea00b 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -480,7 +480,7 @@ var bucky = module.exports = { return } var thread_id = res.thread.get('id') - var dirname = '/bucky/data/' + thread_id + '/' + var dirname = process.env.S3_PATH + '/data/' + thread_id + '/' var promises = req.files.map((file) => { return new Promise( (resolve, reject) => { upload.put({ @@ -499,7 +499,7 @@ var bucky = module.exports = { date: util.now(), size: file.size, privacy: false, - storage: 'i.asdf.us', + storage: process.env.S3_BUCKET, } db.createFile(data).then(function(file){ resolve(file) diff --git a/bucky/db/index.js b/bucky/db/index.js index 51c024b..5e21603 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -172,8 +172,8 @@ 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 srcPath = process.env.S3_PATH + '/data/' + file.get('thread') + '/' + file.get('filename') + var destPath = process.env.S3_PATH + '/data/' + thread_id + '/' + file.get('filename') console.log('moving', srcPath, 'to', destPath) var copyPromise = new Promise((resolve, reject) => { s3client.copy(srcPath, destPath).on('response', function(res){ @@ -207,7 +207,7 @@ db.destroyFiles = function(files){ if (! thread_id || ! filename) { return resolve() } - var filePath = '/bucky/data/' + thread_id + '/' + filename + var filePath = process.env.S3_PATH + '/data/' + thread_id + '/' + filename console.log('delete', filePath) s3client.deleteFile(filePath, function(err, res){ // check `err`, then do `res.pipe(..)` or `res.resume()` or whatever. diff --git a/bucky/util/federate.js b/bucky/util/federate.js index 472c32e..b782801 100644 --- a/bucky/util/federate.js +++ b/bucky/util/federate.js @@ -62,7 +62,7 @@ module.exports = { var promises = files.map(file => { copyFileToS3(file, thread_id) file.set('thread', thread_id) - file.set('storage', 'i.asdf.us') + file.set('storage', process.env.S3_BUCKET) return send("file", file) }) return promises @@ -93,7 +93,7 @@ module.exports = { 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 + const remote_path = process.env.S3_PATH + '/data/' + dst_fn console.log(mime.lookup(file.get('filename'))) upload.client().putBuffer(buffer, remote_path, { 'Content-Length': buffer.length, diff --git a/bucky/util/middleware.js b/bucky/util/middleware.js index 47633da..9872665 100644 --- a/bucky/util/middleware.js +++ b/bucky/util/middleware.js @@ -14,9 +14,19 @@ var middleware = module.exports = { res.locals.env = process.env.NODE_ENV if (req.isAuthenticated()) { res.locals.show_header = true + res.locals.preload = JSON.stringify({ + env: res.locals.env, + s3: { + bucket: process.env.S3_BUCKET, + path: process.env.S3_PATH, + } + }) } else { res.locals.show_header = false + res.locals.preload = JSON.stringify({ + env: res.locals.env, + }) } next() }, |
