]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/utils.js
Server: fix video remoe validation
[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 = {
c4403b29 8 cleanForExit,
441b66f8
C
9 generateRandomString,
10 isTestInstance
cbe2f7c3
C
11}
12
13function generateRandomString (size, callback) {
14 crypto.pseudoRandomBytes(size, function (err, raw) {
15 if (err) return callback(err)
16
17 callback(null, raw.toString('hex'))
18 })
9f10b292 19}
8c308c2b 20
bc503c2a 21function cleanForExit (webtorrentProcess) {
9f10b292 22 logger.info('Gracefully exiting.')
bc503c2a 23 process.kill(-webtorrentProcess.pid)
9f10b292 24}
0ae2e7f7 25
441b66f8
C
26function isTestInstance () {
27 return (process.env.NODE_ENV === 'test')
28}
29
9f10b292 30// ---------------------------------------------------------------------------
c45f7f84 31
9f10b292 32module.exports = utils