switch between s3/local storage in config

This commit is contained in:
mntmn 2018-01-08 12:43:47 +01:00
parent 8ee3386470
commit ffb7f30133
3 changed files with 24 additions and 18 deletions

View File

@ -1,7 +1,9 @@
{ {
"endpoint": "http://localhost:9000", "endpoint": "http://localhost:9000",
"storage_bucket": "my_spacedeck_s3_bucket", "storage_region": "eu-central-1",
"storage_cdn": "xyz.cloudfront.net", "storage_bucket": "my_spacedeck_bucket",
"storage_cdn": "/storage",
"storage_local_path": "./storage",
"google_access" : "", "google_access" : "",
"google_secret" : "", "google_secret" : "",
"admin_pass": "very_secret_admin_password", "admin_pass": "very_secret_admin_password",

View File

@ -1,15 +1,21 @@
'use strict'; 'use strict';
var AWS = require('aws-sdk');
AWS.config.region = 'eu-central-1';
var fs = require('fs'); var fs = require('fs');
var config = require('config'); var config = require('config');
// use AWS S3 or local folder depending on config
if (config.get("storage_local_path")) {
var AWS = require('mock-aws-s3');
AWS.config.basePath = config.get("storage_local_path");
} else {
var AWS = require('aws-sdk');
AWS.config.region = config.get("storage_region");
}
module.exports = { module.exports = {
removeFile: (path, callback) => { removeFile: (path, callback) => {
const s3 = new AWS.S3({ const s3 = new AWS.S3({
region: 'eu-central-1' region: config.get("storage_region")
}); });
const bucket = config.get("storage_bucket"); const bucket = config.get("storage_bucket");
s3.deleteObject({ s3.deleteObject({
@ -39,9 +45,8 @@ module.exports = {
} }
}); });
fileStream.on('open', function () { fileStream.on('open', function () {
// FIXME
var s3 = new AWS.S3({ var s3 = new AWS.S3({
region: 'eu-central-1' region: config.get("storage_region")
}); });
s3.putObject({ s3.putObject({
@ -54,7 +59,7 @@ module.exports = {
console.error(err); console.error(err);
callback(err); callback(err);
}else { }else {
const url = "https://"+ config.get("storage_cdn") + "/" + fileName; const url = config.get("storage_cdn") + "/" + fileName;
console.log("[s3]" + localFilePath + " to " + url); console.log("[s3]" + localFilePath + " to " + url);
callback(null, url); callback(null, url);
} }

View File

@ -6,8 +6,8 @@
"start": "nodemon -e .js,.html bin/www", "start": "nodemon -e .js,.html bin/www",
"test": "mocha" "test": "mocha"
}, },
"engines" : { "engines": {
"node" : ">=7.8.0" "node": ">=7.8.0"
}, },
"dependencies": { "dependencies": {
"archiver": "1.3.0", "archiver": "1.3.0",
@ -28,7 +28,6 @@
"googleapis": "18.0.0", "googleapis": "18.0.0",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-concat": "2.6.0", "gulp-concat": "2.6.0",
"gulp-eslint": "*",
"gulp-express": "0.3.0", "gulp-express": "0.3.0",
"gulp-nodemon": "*", "gulp-nodemon": "*",
"gulp-sass": "^2.0.3", "gulp-sass": "^2.0.3",
@ -40,13 +39,13 @@
"lodash": "^4.3.0", "lodash": "^4.3.0",
"log-timestamp": "latest", "log-timestamp": "latest",
"md5": "2.2.1", "md5": "2.2.1",
"mock-aws-s3": "^2.6.0",
"moment": "2.18.1", "moment": "2.18.1",
"mongoose": "4.9.3", "mongoose": "4.9.3",
"morgan": "1.8.1", "morgan": "1.8.1",
"node-phantom-simple": "2.2.4",
"node-sass-middleware": "0.11.0", "node-sass-middleware": "0.11.0",
"pdfkit": "0.8.0", "pdfkit": "0.8.0",
"validator": "7.0.0",
"node-phantom-simple": "2.2.4",
"phantomjs-prebuilt": "2.1.14", "phantomjs-prebuilt": "2.1.14",
"pm2": "latest", "pm2": "latest",
"qr-image": "3.2.0", "qr-image": "3.2.0",
@ -54,9 +53,11 @@
"request": "2.81.0", "request": "2.81.0",
"sanitize-html": "^1.11.1", "sanitize-html": "^1.11.1",
"serve-favicon": "~2.4.2", "serve-favicon": "~2.4.2",
"swig": "1.4.2", "serve-static": "^1.13.1",
"slug": "0.9.1", "slug": "0.9.1",
"swig": "1.4.2",
"underscore": "1.8.3", "underscore": "1.8.3",
"validator": "7.0.0",
"weak": "1.0.1", "weak": "1.0.1",
"ws": "2.2.3" "ws": "2.2.3"
}, },
@ -65,7 +66,6 @@
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-clean": "^0.3.2", "gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0", "gulp-concat": "^2.6.0",
"gulp-eslint": "^3.0.1",
"gulp-express": "^0.3.0", "gulp-express": "^0.3.0",
"gulp-fingerprint": "^0.3.2", "gulp-fingerprint": "^0.3.2",
"gulp-nodemon": "^2.0.4", "gulp-nodemon": "^2.0.4",
@ -81,8 +81,7 @@
}, },
"description": "", "description": "",
"main": "Gulpfile.js", "main": "Gulpfile.js",
"directories": { "directories": {},
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/spacedeck/spacedeck-open.git" "url": "https://github.com/spacedeck/spacedeck-open.git"