]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/utils.ts
Translated using Weblate (Polish)
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.ts
index 9b89e3e61066907e32612fb1a0b6dd714e29e427..7a4c781ccb8780f4ab6d51b693b945e620348721 100644 (file)
@@ -1,12 +1,12 @@
 import { ResultList } from '../../shared'
-import { CONFIG } from '../initializers'
 import { ApplicationModel } from '../models/application/application'
-import { execPromise, execPromise2, pseudoRandomBytesPromise, sha256 } from './core-utils'
+import { execPromise, execPromise2, randomBytesPromise, sha256 } from './core-utils'
 import { logger } from './logger'
 import { join } from 'path'
 import { Instance as ParseTorrent } from 'parse-torrent'
 import { remove } from 'fs-extra'
 import * as memoizee from 'memoizee'
+import { CONFIG } from '../initializers/config'
 
 function deleteFileAsync (path: string) {
   remove(path)
@@ -14,26 +14,22 @@ function deleteFileAsync (path: string) {
 }
 
 async function generateRandomString (size: number) {
-  const raw = await pseudoRandomBytesPromise(size)
+  const raw = await randomBytesPromise(size)
 
   return raw.toString('hex')
 }
 
-interface FormattableToJSON {
-  toFormattedJSON (args?: any)
+interface FormattableToJSON<U, V> {
+  toFormattedJSON (args?: U): V
 }
 
-function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number, formattedArg?: any) {
-  const formattedObjects: U[] = []
-
-  objects.forEach(object => {
-    formattedObjects.push(object.toFormattedJSON(formattedArg))
-  })
+function getFormattedObjects<U, V, T extends FormattableToJSON<U, V>> (objects: T[], objectsTotal: number, formattedArg?: U) {
+  const formattedObjects = objects.map(o => o.toFormattedJSON(formattedArg))
 
   return {
     total: objectsTotal,
     data: formattedObjects
-  } as ResultList<U>
+  } as ResultList<V>
 }
 
 const getServerActor = memoizee(async function () {
@@ -44,7 +40,7 @@ const getServerActor = memoizee(async function () {
   actor.Account = application.Account
 
   return actor
-})
+}, { promise: true })
 
 function generateVideoImportTmpPath (target: string | ParseTorrent) {
   const id = typeof target === 'string' ? target : target.infoHash