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",
"storage_bucket": "my_spacedeck_s3_bucket",
"storage_cdn": "xyz.cloudfront.net",
"storage_region": "eu-central-1",
"storage_bucket": "my_spacedeck_bucket",
"storage_cdn": "/storage",
"storage_local_path": "./storage",
"google_access" : "",
"google_secret" : "",
"admin_pass": "very_secret_admin_password",

View File

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

View File

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