diff options
Diffstat (limited to 'server/helpers/utils.js')
-rw-r--r-- | server/helpers/utils.js | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/server/helpers/utils.js b/server/helpers/utils.js deleted file mode 100644 index 6d40e8f3f..000000000 --- a/server/helpers/utils.js +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const crypto = require('crypto') | ||
4 | |||
5 | const logger = require('./logger') | ||
6 | |||
7 | const utils = { | ||
8 | badRequest, | ||
9 | createEmptyCallback, | ||
10 | cleanForExit, | ||
11 | generateRandomString, | ||
12 | isTestInstance, | ||
13 | getFormatedObjects | ||
14 | } | ||
15 | |||
16 | function badRequest (req, res, next) { | ||
17 | res.type('json').status(400).end() | ||
18 | } | ||
19 | |||
20 | function generateRandomString (size, callback) { | ||
21 | crypto.pseudoRandomBytes(size, function (err, raw) { | ||
22 | if (err) return callback(err) | ||
23 | |||
24 | callback(null, raw.toString('hex')) | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | function cleanForExit (webtorrentProcess) { | ||
29 | logger.info('Gracefully exiting.') | ||
30 | process.kill(-webtorrentProcess.pid) | ||
31 | } | ||
32 | |||
33 | function createEmptyCallback () { | ||
34 | return function (err) { | ||
35 | if (err) logger.error('Error in empty callback.', { error: err }) | ||
36 | } | ||
37 | } | ||
38 | |||
39 | function isTestInstance () { | ||
40 | return (process.env.NODE_ENV === 'test') | ||
41 | } | ||
42 | |||
43 | function getFormatedObjects (objects, objectsTotal) { | ||
44 | const formatedObjects = [] | ||
45 | |||
46 | objects.forEach(function (object) { | ||
47 | formatedObjects.push(object.toFormatedJSON()) | ||
48 | }) | ||
49 | |||
50 | return { | ||
51 | total: objectsTotal, | ||
52 | data: formatedObjects | ||
53 | } | ||
54 | } | ||
55 | |||
56 | // --------------------------------------------------------------------------- | ||
57 | |||
58 | module.exports = utils | ||