Add: fileDownloadedWebhook (Closes #29)
This commit is contained in:
@@ -16,6 +16,7 @@ const debug = require('debug')('psitransfer:main');
|
||||
const archiver = require('archiver');
|
||||
const zlib = require('zlib');
|
||||
const _ = require('lodash');
|
||||
const axios = require('axios');
|
||||
|
||||
const errorPage = fs.readFileSync(path.join(__dirname, '../public/html/error.html')).toString();
|
||||
const store = new Store(config.uploadDir);
|
||||
@@ -133,6 +134,8 @@ app.get('/files/:fid', async (req, res, next) => {
|
||||
// let tusboy handle HEAD requests with Tus Header
|
||||
if (req.method === 'HEAD' && req.get('Tus-Resumable')) return next();
|
||||
|
||||
const sid = req.params.fid.split('++')[0];
|
||||
|
||||
// Download all files
|
||||
if (req.params.fid.match(/^[a-z0-9+]+\.(tar\.gz|zip)$/)) {
|
||||
const format = req.params.fid.endsWith('.zip') ? 'zip' : 'tar.gz';
|
||||
@@ -178,6 +181,16 @@ app.get('/files/:fid', async (req, res, next) => {
|
||||
await db.updateLastDownload(info.metadata.sid, info.metadata.key);
|
||||
}
|
||||
});
|
||||
|
||||
// Trigger fileDownloadedWebhook
|
||||
if(config.fileDownloadedWebhook) {
|
||||
axios.post(config.fileDownloadedWebhook, {
|
||||
fid: sid,
|
||||
file: '_archive_',
|
||||
date: Date.now()
|
||||
}).catch(err => console.error(err));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
@@ -200,6 +213,15 @@ app.get('/files/:fid', async (req, res, next) => {
|
||||
} else {
|
||||
await db.updateLastDownload(info.metadata.sid, info.metadata.key);
|
||||
}
|
||||
|
||||
// Trigger fileDownloadedWebhook
|
||||
if (config.fileDownloadedWebhook) {
|
||||
axios.post(config.fileDownloadedWebhook, {
|
||||
bucket: sid,
|
||||
file: info.metadata.name,
|
||||
date: Date.now()
|
||||
}).catch(err => console.error(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user