aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/utils.js')
-rw-r--r--server/helpers/utils.js58
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
3const crypto = require('crypto')
4
5const logger = require('./logger')
6
7const utils = {
8 badRequest,
9 createEmptyCallback,
10 cleanForExit,
11 generateRandomString,
12 isTestInstance,
13 getFormatedObjects
14}
15
16function badRequest (req, res, next) {
17 res.type('json').status(400).end()
18}
19
20function 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
28function cleanForExit (webtorrentProcess) {
29 logger.info('Gracefully exiting.')
30 process.kill(-webtorrentProcess.pid)
31}
32
33function createEmptyCallback () {
34 return function (err) {
35 if (err) logger.error('Error in empty callback.', { error: err })
36 }
37}
38
39function isTestInstance () {
40 return (process.env.NODE_ENV === 'test')
41}
42
43function 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
58module.exports = utils