currently not working, decryption seems to fail
This commit is contained in:
parent
0677603d74
commit
39a63cd16e
|
@ -5,6 +5,7 @@ class FileReceiver extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.salt = strToIv(location.pathname.slice(10, -1));
|
this.salt = strToIv(location.pathname.slice(10, -1));
|
||||||
|
window.salt = this.salt;
|
||||||
}
|
}
|
||||||
|
|
||||||
download() {
|
download() {
|
||||||
|
@ -30,11 +31,13 @@ class FileReceiver extends EventEmitter {
|
||||||
let blob = new Blob([this.response]);
|
let blob = new Blob([this.response]);
|
||||||
let fileReader = new FileReader();
|
let fileReader = new FileReader();
|
||||||
fileReader.onload = function() {
|
fileReader.onload = function() {
|
||||||
|
window.data = this.result;
|
||||||
|
console.log(this.result);
|
||||||
resolve({
|
resolve({
|
||||||
data: this.result,
|
data: this.result,
|
||||||
fname: xhr
|
fname: xhr
|
||||||
.getResponseHeader('Content-Disposition')
|
.getResponseHeader('Content-Disposition')
|
||||||
.match(/filename="(.+)"/)[1]
|
.match(/="(.+)"/)[1]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"author": "Mozilla (https://mozilla.org)",
|
"author": "Mozilla (https://mozilla.org)",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"aws-sdk": "^2.62.0",
|
||||||
"body-parser": "^1.17.2",
|
"body-parser": "^1.17.2",
|
||||||
"connect-busboy": "0.0.2",
|
"connect-busboy": "0.0.2",
|
||||||
|
"convict": "^3.0.0",
|
||||||
"express": "^4.15.3",
|
"express": "^4.15.3",
|
||||||
"fs-extra": "^3.0.1",
|
"fs-extra": "^3.0.1",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
const convict = require('convict');
|
||||||
|
|
||||||
|
let conf = convict({
|
||||||
|
aws_credentials: {
|
||||||
|
region: 'us-west-2',
|
||||||
|
bucketName: 'testpilot-p2p'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// var env = conf.get('env');
|
||||||
|
// conf.loadFile('./config/' + env + '.json');
|
||||||
|
|
||||||
|
// Perform validation
|
||||||
|
conf.validate({allowed: 'strict'});
|
||||||
|
|
||||||
|
module.exports = conf;
|
|
@ -1,15 +1,24 @@
|
||||||
const express = require('express');
|
const express = require("express")
|
||||||
const busboy = require('connect-busboy');
|
const busboy = require("connect-busboy");
|
||||||
const path = require('path');
|
const path = require("path");
|
||||||
const fs = require('fs-extra');
|
const fs = require("fs-extra");
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require("body-parser");
|
||||||
const crypto = require('crypto');
|
const crypto = require("crypto");
|
||||||
|
const conf = require('./config.js');
|
||||||
|
const stream = require('stream');
|
||||||
|
|
||||||
const app = express();
|
let aws_credentials = conf.get('aws_credentials');
|
||||||
const redis = require('redis'),
|
|
||||||
client = redis.createClient();
|
|
||||||
|
|
||||||
client.on('error', err => {
|
const AWS = require('aws-sdk');
|
||||||
|
AWS.config.loadFromPath('../../.aws/credentials');
|
||||||
|
const s3 = new AWS.S3();
|
||||||
|
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
const redis = require("redis"),
|
||||||
|
redis_client = redis.createClient();
|
||||||
|
|
||||||
|
redis_client.on("error", (err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,22 +37,36 @@ app.get('/assets/download/:id', (req, res) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.hget(id, 'filename', (err, reply) => {
|
let params = {
|
||||||
// maybe some expiration logic too
|
Bucket: aws_credentials.bucketName,
|
||||||
if (!reply) {
|
Key: req.params.id
|
||||||
res.sendStatus(404);
|
}
|
||||||
} else {
|
|
||||||
res.setHeader('Content-Disposition', 'attachment; filename=' + reply);
|
|
||||||
res.setHeader('Content-Type', 'application/octet-stream');
|
|
||||||
|
|
||||||
res.download(__dirname + '/../static/' + id, reply, err => {
|
s3.getObject(params, function(err, data) {
|
||||||
if (!err) {
|
if (err) {
|
||||||
client.del(id);
|
console.log(err, err.stack); // an error occurred
|
||||||
fs.unlinkSync(__dirname + '/../static/' + id);
|
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
|
res.writeHead(200, {"Content-Disposition": "attachment; filename=response", //+ reply,
|
||||||
|
"Content-Type": "application/octet-stream"});
|
||||||
|
// res.setHeader("Content-Type", "application/octet-stream");
|
||||||
|
res.end(new Buffer(data.Body))
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
|
// redis_client.hget(id, "filename", (err, reply) => { // maybe some expiration logic too
|
||||||
|
// if (!reply) {
|
||||||
|
// res.sendStatus(404);
|
||||||
|
// } else {
|
||||||
|
|
||||||
|
// res.download(__dirname + "/../static/" + id, reply, (err) => {
|
||||||
|
// if (!err) {
|
||||||
|
// redis_client.del(id);
|
||||||
|
// fs.unlinkSync(__dirname + "/../static/" + id);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// })
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/delete/:id', (req, res) => {
|
app.post('/delete/:id', (req, res) => {
|
||||||
|
@ -60,18 +83,28 @@ app.post('/delete/:id', (req, res) => {
|
||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
client.hget(id, 'delete', (err, reply) => {
|
client.hget(id, 'delete', (err, reply) => {
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
} else {
|
} else {
|
||||||
client.del(id);
|
client.del(id);
|
||||||
fs.unlinkSync(__dirname + '/../static/' + id);
|
fs.unlinkSync(__dirname + '/../static/' + id);
|
||||||
|
=======
|
||||||
|
redis_client.hget(id, "delete", (err, reply) => {
|
||||||
|
if (!reply) {
|
||||||
|
res.sendStatus(404);
|
||||||
|
} else {
|
||||||
|
redis_client.del(id);
|
||||||
|
fs.unlinkSync(__dirname + "/../static/" + id);
|
||||||
|
>>>>>>> currently not working, decryption seems to fail
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/upload/:id', (req, res, next) => {
|
app.post("/upload/:id", (req, res, next) => {
|
||||||
|
|
||||||
if (!validateID(req.params.id)){
|
if (!validateID(req.params.id)){
|
||||||
res.send(404);
|
res.send(404);
|
||||||
return;
|
return;
|
||||||
|
@ -79,29 +112,46 @@ app.post('/upload/:id', (req, res, next) => {
|
||||||
|
|
||||||
let fstream;
|
let fstream;
|
||||||
req.pipe(req.busboy);
|
req.pipe(req.busboy);
|
||||||
req.busboy.on('file', (fieldname, file, filename) => {
|
req.busboy.on("file", (fieldname, file, filename) => {
|
||||||
console.log('Uploading: ' + filename);
|
console.log("Uploading: " + filename);
|
||||||
|
|
||||||
//Path where image will be uploaded
|
|
||||||
fstream = fs.createWriteStream(__dirname + '/../static/' + req.params.id);
|
let params = {
|
||||||
|
Bucket: aws_credentials.bucketName,
|
||||||
|
Key: req.params.id,
|
||||||
|
Body: file
|
||||||
|
}
|
||||||
|
|
||||||
|
s3.upload(params, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err, err.stack); // an error occurred
|
||||||
|
} else {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
fstream = fs.createWriteStream(__dirname + "/../static/" + req.params.id);
|
||||||
file.pipe(fstream);
|
file.pipe(fstream);
|
||||||
fstream.on('close', () => {
|
fstream.on("close", () => {
|
||||||
let id = req.params.id;
|
let id = req.params.id;
|
||||||
let uuid = crypto.randomBytes(10).toString('hex');
|
let uuid = crypto.randomBytes(10).toString('hex');
|
||||||
|
|
||||||
client.hmset([id, 'filename', filename, 'delete', uuid]);
|
redis_client.hmset([id, "filename", filename, "delete", uuid]);
|
||||||
|
|
||||||
// delete the file off the server in 24 hours
|
// delete the file off the server in 24 hours
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
// fs.unlinkSync(__dirname + "/static/" + id);
|
// fs.unlinkSync(__dirname + "/static/" + id);
|
||||||
// }, 86400000);
|
// }, 86400000);
|
||||||
|
|
||||||
client.expire(id, 86400000);
|
redis_client.expire(id, 86400000);
|
||||||
console.log('Upload Finished of ' + filename);
|
console.log("Upload Finished of " + filename);
|
||||||
res.send(uuid);
|
res.send(uuid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(3000, () => {
|
app.listen(3000, () => {
|
||||||
console.log('Portal app listening on port 3000!');
|
console.log('Portal app listening on port 3000!');
|
||||||
|
|
Loading…
Reference in New Issue