]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/utils.js
Server: move remote routes in their own directory
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.js
CommitLineData
9f10b292 1'use strict'
8c308c2b 2
cbe2f7c3
C
3const crypto = require('crypto')
4
f0f5567b 5const logger = require('./logger')
8c308c2b 6
f0f5567b 7const utils = {
a6fd2b30 8 badRequest,
c4403b29 9 cleanForExit,
441b66f8
C
10 generateRandomString,
11 isTestInstance
cbe2f7c3
C
12}
13
a6fd2b30
C
14function badRequest (req, res, next) {
15 res.type('json').status(400).end()
16}
17
cbe2f7c3
C
18function 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 26function cleanForExit (webtorrentProcess) {
9f10b292 27 logger.info('Gracefully exiting.')
bc503c2a 28 process.kill(-webtorrentProcess.pid)
9f10b292 29}
0ae2e7f7 30
441b66f8
C
31function isTestInstance () {
32 return (process.env.NODE_ENV === 'test')
33}
34
9f10b292 35// ---------------------------------------------------------------------------
c45f7f84 36
9f10b292 37module.exports = utils