added aad encryption
This commit is contained in:
parent
50995238bd
commit
34c367c49f
5 changed files with 52 additions and 10 deletions
|
@ -78,14 +78,17 @@ app.get('/assets/download/:id', (req, res) => {
|
|||
return;
|
||||
}
|
||||
|
||||
storage
|
||||
.filename(id)
|
||||
.then(reply => {
|
||||
Promise.all([
|
||||
storage.filename(id),
|
||||
storage.aad(id)])
|
||||
.then(([reply, aad]) => {
|
||||
storage.length(id).then(contentLength => {
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Disposition': 'attachment; filename=' + reply,
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Length': contentLength
|
||||
'Content-Length': contentLength,
|
||||
'Additional-Data': aad
|
||||
});
|
||||
const file_stream = storage.get(id);
|
||||
|
||||
|
@ -142,16 +145,22 @@ app.post('/upload/:id', (req, res, next) => {
|
|||
}
|
||||
|
||||
req.pipe(req.busboy);
|
||||
|
||||
req.busboy.on('field', (fieldname, value) => {
|
||||
storage.setField(req.params.id, fieldname, value);
|
||||
})
|
||||
|
||||
req.busboy.on('file', (fieldname, file, filename) => {
|
||||
log.info('Uploading:', req.params.id);
|
||||
|
||||
const protocol = conf.env === 'production' ? 'https' : req.protocol;
|
||||
const url = `${protocol}://${req.get('host')}/download/${req.params.id}/`;
|
||||
|
||||
storage.set(req.params.id, file, filename, url).then(linkAndID => {
|
||||
res.json(linkAndID);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
app.get('/__lbheartbeat__', (req, res) => {
|
||||
|
|
|
@ -27,6 +27,8 @@ if (conf.s3_bucket) {
|
|||
length: awsLength,
|
||||
get: awsGet,
|
||||
set: awsSet,
|
||||
aad: aad,
|
||||
setField: setField,
|
||||
delete: awsDelete,
|
||||
forceDelete: awsForceDelete,
|
||||
ping: awsPing
|
||||
|
@ -38,6 +40,8 @@ if (conf.s3_bucket) {
|
|||
length: localLength,
|
||||
get: localGet,
|
||||
set: localSet,
|
||||
aad: aad,
|
||||
setField: setField,
|
||||
delete: localDelete,
|
||||
forceDelete: localForceDelete,
|
||||
ping: localPing
|
||||
|
@ -68,6 +72,22 @@ function exists(id) {
|
|||
});
|
||||
}
|
||||
|
||||
function setField(id, key, value) {
|
||||
redis_client.hset(id, key, value);
|
||||
}
|
||||
|
||||
function aad(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
redis_client.hget(id, 'aad', (err, reply) => {
|
||||
if (!err) {
|
||||
resolve(reply);
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function localLength(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
|
@ -86,7 +106,7 @@ function localSet(id, file, filename, url) {
|
|||
return new Promise((resolve, reject) => {
|
||||
const fstream = fs.createWriteStream(path.join(__dirname, '../static', id));
|
||||
file.pipe(fstream);
|
||||
fstream.on('close', () => {
|
||||
fstream.on('close', () => {
|
||||
const uuid = crypto.randomBytes(10).toString('hex');
|
||||
|
||||
redis_client.hmset([id, 'filename', filename, 'delete', uuid]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue