UNPKG

739 BJavaScriptView Raw
1const fetch = require('node-fetch');
2const { print, l10n } = require('../..');
3const crypto = require('crypto');
4
5module.exports = (thread, config) => {
6 print.debug('dmhy:downloaders:webhook:thread', thread);
7 print.debug('dmhy:downloaders:webhook:config', config);
8
9 const tok = crypto
10 .createHash('sha1')
11 .update(config['webhook-token'])
12 .digest('hex');
13
14 return fetch(config['webhook-url'], {
15 method: 'POST',
16 body: JSON.stringify(thread),
17 headers: {
18 'Content-Type': 'application/json',
19 'x-dmhy-token': tok,
20 },
21 })
22 .then(() => print.success(l10n('DOWNLOADER_DL_SUCCESS', { title: thread.title })))
23 .catch(() => print.error(l10n('DOWNLOADER_DL_FAILED', { title: thread.title })));
24};