basic import functionality; dockerfile fixes; session and cookie handling fixes

This commit is contained in:
Lukas F. Hartmann
2018-03-30 22:34:27 +02:00
18 changed files with 209 additions and 70 deletions

View File

@@ -2,21 +2,40 @@
var fs = require('fs');
var config = require('config');
var s3 = null;
// 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");
s3 = new AWS.S3();
} else {
var AWS = require('aws-sdk');
AWS.config.region = config.get("storage_region");
var storage_endpoint = config.get("storage_endpoint");
const ep = new AWS.Endpoint(storage_endpoint);
AWS.config.update(new AWS.Config({
accessKeyId: process.env.MINIO_ACCESS_KEY,
secretAccessKey: process.env.MINIO_SECRET_KEY,
region: config.get("storage_region"),
s3ForcePathStyle: true,
signatureVersion: 'v4'
}));
s3 = new AWS.S3({
endpoint: ep
});
}
s3.createBucket({
Bucket: config.get("storage_bucket"),
ACL: "public-read",
GrantRead: "*"
}, (err,res) => {
console.log("createBucket",err,res);
});
module.exports = {
removeFile: (path, callback) => {
const s3 = new AWS.S3({
region: config.get("storage_region")
});
const bucket = config.get("storage_bucket");
s3.deleteObject({
Bucket: bucket, Key: path
@@ -34,7 +53,7 @@ module.exports = {
callback({error:"missing path"}, null);
return;
}
console.log("[s3] uploading", localFilePath, " to ", fileName);
console.log("[storage] uploading", localFilePath, " to ", fileName);
const bucket = config.get("storage_bucket");
const fileStream = fs.createReadStream(localFilePath);
@@ -45,10 +64,6 @@ module.exports = {
}
});
fileStream.on('open', function () {
var s3 = new AWS.S3({
region: config.get("storage_region")
});
s3.putObject({
Bucket: bucket,
Key: fileName,
@@ -58,7 +73,7 @@ module.exports = {
if (err){
console.error(err);
callback(err);
}else {
} else {
const url = config.get("storage_cdn") + "/" + fileName;
console.log("[s3]" + localFilePath + " to " + url);
callback(null, url);