X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Futils.js;fp=server%2Fhelpers%2Futils.js;h=0000000000000000000000000000000000000000;hb=65fcc3119c334b75dd13bcfdebf186afdc580a8f;hp=6d40e8f3fce3451f40b7e541fa6481f05cc6fddf;hpb=d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73;p=github%2FChocobozzz%2FPeerTube.git 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 @@ -'use strict' - -const crypto = require('crypto') - -const logger = require('./logger') - -const utils = { - badRequest, - createEmptyCallback, - cleanForExit, - generateRandomString, - isTestInstance, - getFormatedObjects -} - -function badRequest (req, res, next) { - res.type('json').status(400).end() -} - -function generateRandomString (size, callback) { - crypto.pseudoRandomBytes(size, function (err, raw) { - if (err) return callback(err) - - callback(null, raw.toString('hex')) - }) -} - -function cleanForExit (webtorrentProcess) { - logger.info('Gracefully exiting.') - process.kill(-webtorrentProcess.pid) -} - -function createEmptyCallback () { - return function (err) { - if (err) logger.error('Error in empty callback.', { error: err }) - } -} - -function isTestInstance () { - return (process.env.NODE_ENV === 'test') -} - -function getFormatedObjects (objects, objectsTotal) { - const formatedObjects = [] - - objects.forEach(function (object) { - formatedObjects.push(object.toFormatedJSON()) - }) - - return { - total: objectsTotal, - data: formatedObjects - } -} - -// --------------------------------------------------------------------------- - -module.exports = utils