diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/helpers/utils.js | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
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 | ||