]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
8c308c2b | 2 | |
cbe2f7c3 C |
3 | const crypto = require('crypto') |
4 | ||
f0f5567b | 5 | const logger = require('./logger') |
8c308c2b | 6 | |
f0f5567b | 7 | const utils = { |
a6fd2b30 | 8 | badRequest, |
c4403b29 | 9 | cleanForExit, |
441b66f8 C |
10 | generateRandomString, |
11 | isTestInstance | |
cbe2f7c3 C |
12 | } |
13 | ||
a6fd2b30 C |
14 | function badRequest (req, res, next) { |
15 | res.type('json').status(400).end() | |
16 | } | |
17 | ||
cbe2f7c3 C |
18 | function generateRandomString (size, callback) { |
19 | crypto.pseudoRandomBytes(size, function (err, raw) { | |
20 | if (err) return callback(err) | |
21 | ||
22 | callback(null, raw.toString('hex')) | |
23 | }) | |
9f10b292 | 24 | } |
8c308c2b | 25 | |
bc503c2a | 26 | function cleanForExit (webtorrentProcess) { |
9f10b292 | 27 | logger.info('Gracefully exiting.') |
bc503c2a | 28 | process.kill(-webtorrentProcess.pid) |
9f10b292 | 29 | } |
0ae2e7f7 | 30 | |
441b66f8 C |
31 | function isTestInstance () { |
32 | return (process.env.NODE_ENV === 'test') | |
33 | } | |
34 | ||
9f10b292 | 35 | // --------------------------------------------------------------------------- |
c45f7f84 | 36 | |
9f10b292 | 37 | module.exports = utils |