]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/utils.js
Server: add video abuse support
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.js
index 9c2d402e3105047615d26bfe4ebd016deed2810d..9f4b145825758c304c4ef1aeb18402d16f90e364 100644 (file)
@@ -5,8 +5,15 @@ const crypto = require('crypto')
 const logger = require('./logger')
 
 const utils = {
+  badRequest,
   cleanForExit,
-  generateRandomString
+  generateRandomString,
+  isTestInstance,
+  getFormatedObjects
+}
+
+function badRequest (req, res, next) {
+  res.type('json').status(400).end()
 }
 
 function generateRandomString (size, callback) {
@@ -22,6 +29,23 @@ function cleanForExit (webtorrentProcess) {
   process.kill(-webtorrentProcess.pid)
 }
 
+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