Add: fileDownloadedWebhook (Closes #29)
This commit is contained in:
@@ -38,7 +38,10 @@ const config = {
|
|||||||
// set to false to disable logging
|
// set to false to disable logging
|
||||||
"accessLog": ':date[iso] :method :url :status :response-time :remote-addr',
|
"accessLog": ':date[iso] :method :url :status :response-time :remote-addr',
|
||||||
//use to set custom upload url
|
//use to set custom upload url
|
||||||
"uploadAppPath": '/'
|
"uploadAppPath": '/',
|
||||||
|
// download notification webhook
|
||||||
|
// invokes an HTTP POST to this url whenever a file was downloaded
|
||||||
|
"fileDownloadedWebhook": null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const debug = require('debug')('psitransfer:main');
|
|||||||
const archiver = require('archiver');
|
const archiver = require('archiver');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
const errorPage = fs.readFileSync(path.join(__dirname, '../public/html/error.html')).toString();
|
const errorPage = fs.readFileSync(path.join(__dirname, '../public/html/error.html')).toString();
|
||||||
const store = new Store(config.uploadDir);
|
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
|
// let tusboy handle HEAD requests with Tus Header
|
||||||
if (req.method === 'HEAD' && req.get('Tus-Resumable')) return next();
|
if (req.method === 'HEAD' && req.get('Tus-Resumable')) return next();
|
||||||
|
|
||||||
|
const sid = req.params.fid.split('++')[0];
|
||||||
|
|
||||||
// Download all files
|
// Download all files
|
||||||
if (req.params.fid.match(/^[a-z0-9+]+\.(tar\.gz|zip)$/)) {
|
if (req.params.fid.match(/^[a-z0-9+]+\.(tar\.gz|zip)$/)) {
|
||||||
const format = req.params.fid.endsWith('.zip') ? 'zip' : 'tar.gz';
|
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);
|
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) {
|
catch (e) {
|
||||||
@@ -200,6 +213,15 @@ app.get('/files/:fid', async (req, res, next) => {
|
|||||||
} else {
|
} else {
|
||||||
await db.updateLastDownload(info.metadata.sid, info.metadata.key);
|
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) {
|
catch (e) {
|
||||||
|
|||||||
32
package-lock.json
generated
32
package-lock.json
generated
@@ -88,6 +88,15 @@
|
|||||||
"lodash": "^4.17.10"
|
"lodash": "^4.17.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"axios": {
|
||||||
|
"version": "0.18.0",
|
||||||
|
"resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
|
||||||
|
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
|
||||||
|
"requires": {
|
||||||
|
"follow-redirects": "^1.3.0",
|
||||||
|
"is-buffer": "^1.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||||
@@ -572,6 +581,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"follow-redirects": {
|
||||||
|
"version": "1.5.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||||
|
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
||||||
|
"requires": {
|
||||||
|
"debug": "=3.1.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"for-each": {
|
"for-each": {
|
||||||
"version": "0.3.2",
|
"version": "0.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.2.tgz",
|
||||||
@@ -707,6 +734,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz",
|
||||||
"integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4="
|
"integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4="
|
||||||
},
|
},
|
||||||
|
"is-buffer": {
|
||||||
|
"version": "1.1.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||||
|
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||||
|
},
|
||||||
"is-callable": {
|
"is-callable": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.3.tgz",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"archiver": "^3.0.0",
|
"archiver": "^3.0.0",
|
||||||
|
"axios": "^0.18.0",
|
||||||
"compression": "^1.7.3",
|
"compression": "^1.7.3",
|
||||||
"crypto-js": "^3.1.9-1",
|
"crypto-js": "^3.1.9-1",
|
||||||
"debug": "^4.1.0",
|
"debug": "^4.1.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user