summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.env-sample1
-rw-r--r--README6
-rw-r--r--bucky/app/bucky.js4
-rw-r--r--bucky/db/index.js6
-rw-r--r--bucky/util/federate.js4
-rw-r--r--bucky/util/middleware.js10
-rw-r--r--public/assets/js/index.js1
-rw-r--r--public/assets/js/lib/sdk/_sdk.js13
-rw-r--r--public/assets/js/util/format.js4
-rw-r--r--views/partials/footer.ejs1
10 files changed, 36 insertions, 14 deletions
diff --git a/.env-sample b/.env-sample
index 3d50c68..b9e9aad 100644
--- a/.env-sample
+++ b/.env-sample
@@ -6,4 +6,5 @@ HOST_NAME=lvh.me
S3_KEY=
S3_SECRET=
S3_BUCKET=
+S3_PATH=/bucky/
SESSIONS_IN_MEMORY=yes
diff --git a/README b/README
index 66cf52a..d1d5fdf 100644
--- a/README
+++ b/README
@@ -21,6 +21,8 @@ GRANT ALL PRIVILEGES ON bucky.* TO 'carbon'@'localhost';
Copy .env-sample to .env and edit the values accordingly.
+PLEASE change the value of S3_PATH to if you reuse S3 buckets.
+
#### Loading an old bucky db dump
```
@@ -51,7 +53,7 @@ You may have to include the .so files for bdb: `export LD_LIBRARY_PATH=/var/www/
npm start
```
-Server will be running at http://lvh.me:5000/ (or whatever port you set in the .env)
+Server will be running at http://localhost:5000/ aka http://lvh.me:5000/ (or whatever port you set in the .env)
-In production I use something to daemonize the node server, such as pm2 (provides nice dashboard with uptime, restarts, saves logs, etc). Run the web server on a high port and then put it behind NGINX.
+In production I use something to daemonize the node server, such as pm2 (provides nice dashboard with uptime, restarts, saves logs, etc).
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()
},
diff --git a/public/assets/js/index.js b/public/assets/js/index.js
index 06f2158..51c2226 100644
--- a/public/assets/js/index.js
+++ b/public/assets/js/index.js
@@ -12,6 +12,7 @@ var app = (function(){
set_background_color_from_time()
auth.init(app.ready)
+ sdk.init()
}
app.ready = function(){
diff --git a/public/assets/js/lib/sdk/_sdk.js b/public/assets/js/lib/sdk/_sdk.js
index 06726d8..a418695 100644
--- a/public/assets/js/lib/sdk/_sdk.js
+++ b/public/assets/js/lib/sdk/_sdk.js
@@ -5,8 +5,15 @@ var sdk = (function(){
var endpoint = window.location.origin
- sdk.init = function(opt){
- switch (sdk.env = opt.env || "development") {
+ sdk.init = function(){
+ try {
+ const preload = document.querySelector('#preload').getAttribute('payload')
+ sdk.opt = JSON.parse(preload)
+ } catch (e) {
+ console.error("preload error", e)
+ sdk.opt = { s3: {} }
+ }
+ switch (sdk.env = sdk.opt.env || "development") {
case 'test':
break
default:
@@ -22,7 +29,7 @@ var sdk = (function(){
}
sdk.image = function(file, size){
- return "https://i.asdf.us/bucky/data/" + file.thread + "/" + file.id
+ return "https://" + sdk.opt.s3.bucket + sdk.opt.s3.path + "/data/" + file.thread + "/" + file.id
}
// $.ajaxSetup({
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
index 837bf5d..a2da53a 100644
--- a/public/assets/js/util/format.js
+++ b/public/assets/js/util/format.js
@@ -238,7 +238,7 @@ function is_image(url){
}
function make_link(file){
if (file.storage) {
- return "//s3.amazonaws.com/" + file.storage + "/bucky/data/" + file.thread + "/" + encodeURIComponent(file.filename)
+ return "//s3.amazonaws.com/" + file.storage + sdk.opt.s3.path + "/data/" + file.thread + "/" + encodeURIComponent(file.filename)
}
if (file.filename.indexOf("http") !== 0) {
return "/data/" + file.thread + "/" + encodeURIComponent(file.filename)
@@ -250,7 +250,7 @@ function profile_image(username){
}
function make_thumb(file){
if (file.storage) {
- return "//s3.amazonaws.com/" + file.storage + "/bucky/data/" + file.thread + "/" + encodeURIComponent(file.filename)
+ return "//s3.amazonaws.com/" + file.storage + sdk.opt.s3.path + "/data/" + file.thread + "/" + encodeURIComponent(file.filename)
}
if (file.filename.indexOf("http") !== 0) {
return "/data/" + file.thread + "/" + file.filename
diff --git a/views/partials/footer.ejs b/views/partials/footer.ejs
index d5d82d0..860f90b 100644
--- a/views/partials/footer.ejs
+++ b/views/partials/footer.ejs
@@ -1,6 +1,7 @@
</content>
<% include ../partials/404 %>
</body>
+<script type="text/json" id="preload" payload="<%= preload %>"></script>
<% if (env == 'production') { %>
<script src="/assets/min/app.min.js"></script>
<% } else { %>