]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/core-utils.ts
Check live duration and size
[github/Chocobozzz/PeerTube.git] / server / helpers / core-utils.ts
index 2cecea4500bc1d64c41693a72064f89c5a920ded..e1c15a6ebf1aa08c2c86b22af1448d970aa211f1 100644 (file)
@@ -1,7 +1,7 @@
 /* eslint-disable no-useless-call */
 
 /*
-  Different from 'utils' because we don't not import other PeerTube modules.
+  Different from 'utils' because we don't import other PeerTube modules.
   Useful to avoid circular dependencies.
 */
 
@@ -41,6 +41,7 @@ const timeTable = {
 }
 
 export function parseDurationToMs (duration: number | string): number {
+  if (duration === null) return null
   if (typeof duration === 'number') return duration
 
   if (typeof duration === 'string') {
@@ -175,6 +176,16 @@ function pageToStartAndCount (page: number, itemsPerPage: number) {
   return { start, count: itemsPerPage }
 }
 
+function mapToJSON (map: Map<any, any>) {
+  const obj: any = {}
+
+  for (const [ k, v ] of map) {
+    obj[k] = v
+  }
+
+  return obj
+}
+
 function buildPath (path: string) {
   if (isAbsolute(path)) return path
 
@@ -263,6 +274,7 @@ export {
 
   sha256,
   sha1,
+  mapToJSON,
 
   promisify0,
   promisify1,