]> 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 94ceb15e0cbe560b5817431c63b6f9796569e99a..7a4c781ccb8780f4ab6d51b693b945e620348721 100644 (file)
@@ -1,6 +1,6 @@
 import { ResultList } from '../../shared'
 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'
@@ -14,23 +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) }
-function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number, formattedArg?: any) {
-  const formattedObjects: U[] = []
+interface FormattableToJSON<U, V> {
+  toFormattedJSON (args?: U): V
+}
 
-  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 () {
@@ -41,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