]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/utils.ts
Add plugin static files cache
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.ts
index 94ceb15e0cbe560b5817431c63b6f9796569e99a..1464b147728e0cefbac7c7c4b6c97b24d7676ca3 100644 (file)
@@ -19,18 +19,14 @@ async function generateRandomString (size: number) {
   return raw.toString('hex')
 }
 
-interface FormattableToJSON { toFormattedJSON (args?: any) }
-function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number, formattedArg?: any) {
-  const formattedObjects: U[] = []
-
-  objects.forEach(object => {
-    formattedObjects.push(object.toFormattedJSON(formattedArg))
-  })
+interface FormattableToJSON<U, V> { toFormattedJSON (args?: U): V }
+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 () {