Added multiple download option

This commit is contained in:
Danny Coates 2017-11-30 13:41:09 -08:00
parent beb3a6e67b
commit 7b4060f9e1
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
22 changed files with 1159 additions and 453 deletions

View file

@ -19,12 +19,12 @@ module.exports = async function(req, res) {
const hmac = crypto.createHmac('sha256', Buffer.from(meta.auth, 'base64'));
hmac.update(Buffer.from(meta.nonce, 'base64'));
const verifyHash = hmac.digest();
const nonce = crypto.randomBytes(16).toString('base64');
storage.setField(id, 'nonce', nonce);
if (!verifyHash.equals(Buffer.from(auth, 'base64'))) {
res.set('WWW-Authenticate', `send-v1 ${nonce}`);
res.set('WWW-Authenticate', `send-v1 ${meta.nonce}`);
return res.sendStatus(401);
}
const nonce = crypto.randomBytes(16).toString('base64');
storage.setField(id, 'nonce', nonce);
const contentLength = await storage.length(id);
res.writeHead(200, {
'Content-Disposition': 'attachment',
@ -36,10 +36,16 @@ module.exports = async function(req, res) {
const file_stream = storage.get(id);
file_stream.on('end', async () => {
const dl = (+meta.dl || 0) + 1;
const dlimit = +meta.dlimit || 1;
try {
await storage.forceDelete(id);
if (dl >= dlimit) {
await storage.forceDelete(id);
} else {
await storage.setField(id, 'dl', dl);
}
} catch (e) {
log.info('DeleteError:', id);
log.info('StorageError:', id);
}
});