currently not working, decryption seems to fail

This commit is contained in:
Abhinav Adduri 2017-06-05 15:35:36 -07:00 committed by Danny Coates
parent 0677603d74
commit 39a63cd16e
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
4 changed files with 119 additions and 48 deletions

View File

@ -5,6 +5,7 @@ class FileReceiver extends EventEmitter {
constructor() {
super();
this.salt = strToIv(location.pathname.slice(10, -1));
window.salt = this.salt;
}
download() {
@ -30,11 +31,13 @@ class FileReceiver extends EventEmitter {
let blob = new Blob([this.response]);
let fileReader = new FileReader();
fileReader.onload = function() {
window.data = this.result;
console.log(this.result);
resolve({
data: this.result,
fname: xhr
.getResponseHeader('Content-Disposition')
.match(/filename="(.+)"/)[1]
.match(/="(.+)"/)[1]
});
};

View File

@ -4,8 +4,10 @@
"version": "1.0.0",
"author": "Mozilla (https://mozilla.org)",
"dependencies": {
"aws-sdk": "^2.62.0",
"body-parser": "^1.17.2",
"connect-busboy": "0.0.2",
"convict": "^3.0.0",
"express": "^4.15.3",
"fs-extra": "^3.0.1",
"path": "^0.12.7",

16
server/config.js Normal file
View File

@ -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;

View File

@ -1,15 +1,24 @@
const express = require('express');
const busboy = require('connect-busboy');
const path = require('path');
const fs = require('fs-extra');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const express = require("express")
const busboy = require("connect-busboy");
const path = require("path");
const fs = require("fs-extra");
const bodyParser = require("body-parser");
const crypto = require("crypto");
const conf = require('./config.js');
const stream = require('stream');
const app = express();
const redis = require('redis'),
client = redis.createClient();
let aws_credentials = conf.get('aws_credentials');
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);
});
@ -28,22 +37,36 @@ app.get('/assets/download/:id', (req, res) => {
return;
}
client.hget(id, 'filename', (err, reply) => {
// maybe some expiration logic too
if (!reply) {
res.sendStatus(404);
} else {
res.setHeader('Content-Disposition', 'attachment; filename=' + reply);
res.setHeader('Content-Type', 'application/octet-stream');
let params = {
Bucket: aws_credentials.bucketName,
Key: req.params.id
}
res.download(__dirname + '/../static/' + id, reply, err => {
if (!err) {
client.del(id);
fs.unlinkSync(__dirname + '/../static/' + id);
}
});
s3.getObject(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
}
});
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) => {
@ -60,45 +83,72 @@ app.post('/delete/:id', (req, res) => {
res.sendStatus(404);
}
<<<<<<< HEAD
client.hget(id, 'delete', (err, reply) => {
if (!reply) {
res.sendStatus(404);
} else {
client.del(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);
}
});
});
app.post('/upload/:id', (req, res, next) => {
if (!validateID(req.params.id)) {
res.send(404);
return;
}
app.post("/upload/:id", (req, res, next) => {
let fstream;
req.pipe(req.busboy);
req.busboy.on('file', (fieldname, file, filename) => {
console.log('Uploading: ' + filename);
if (!validateID(req.params.id)){
res.send(404);
return;
}
//Path where image will be uploaded
fstream = fs.createWriteStream(__dirname + '/../static/' + req.params.id);
file.pipe(fstream);
fstream.on('close', () => {
let id = req.params.id;
let uuid = crypto.randomBytes(10).toString('hex');
let fstream;
req.pipe(req.busboy);
req.busboy.on("file", (fieldname, file, filename) => {
console.log("Uploading: " + filename);
client.hmset([id, 'filename', filename, 'delete', uuid]);
// delete the file off the server in 24 hours
// setTimeout(() => {
// fs.unlinkSync(__dirname + "/static/" + id);
// }, 86400000);
let params = {
Bucket: aws_credentials.bucketName,
Key: req.params.id,
Body: file
}
client.expire(id, 86400000);
console.log('Upload Finished of ' + filename);
res.send(uuid);
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);
fstream.on("close", () => {
let id = req.params.id;
let uuid = crypto.randomBytes(10).toString('hex');
redis_client.hmset([id, "filename", filename, "delete", uuid]);
// delete the file off the server in 24 hours
// setTimeout(() => {
// fs.unlinkSync(__dirname + "/static/" + id);
// }, 86400000);
redis_client.expire(id, 86400000);
console.log("Upload Finished of " + filename);
res.send(uuid);
});
});
});
});