]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/utils.ts
Add 30 fps limit in transcoding
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.ts
index 7a32e286ca56a9c5c341dd03699bfad7a37b293f..3b618360bc25c52b37a86734c7a00d430e9cf958 100644 (file)
@@ -3,7 +3,7 @@ import * as multer from 'multer'
 import { Model } from 'sequelize-typescript'
 import { ResultList } from '../../shared'
 import { VideoResolution } from '../../shared/models/videos'
-import { CONFIG, REMOTE_SCHEME, VIDEO_MIMETYPE_EXT } from '../initializers'
+import { CONFIG, REMOTE_SCHEME } from '../initializers'
 import { UserModel } from '../models/account/user'
 import { ActorModel } from '../models/activitypub/actor'
 import { ApplicationModel } from '../models/application/application'
@@ -27,10 +27,14 @@ function badRequest (req: express.Request, res: express.Response, next: express.
   return res.type('json').status(400).end()
 }
 
-function createReqFiles (fieldName: string, storageDir: string, mimeTypes: { [ id: string ]: string }) {
+function createReqFiles (
+  fieldNames: string[],
+  mimeTypes: { [ id: string ]: string },
+  destinations: { [ fieldName: string ]: string }
+) {
   const storage = multer.diskStorage({
     destination: (req, file, cb) => {
-      cb(null, storageDir)
+      cb(null, destinations[file.fieldname])
     },
 
     filename: async (req, file, cb) => {
@@ -48,7 +52,15 @@ function createReqFiles (fieldName: string, storageDir: string, mimeTypes: { [ i
     }
   })
 
-  return multer({ storage }).fields([{ name: fieldName, maxCount: 1 }])
+  const fields = []
+  for (const fieldName of fieldNames) {
+    fields.push({
+      name: fieldName,
+      maxCount: 1
+    })
+  }
+
+  return multer({ storage }).fields(fields)
 }
 
 async function generateRandomString (size: number) {
@@ -104,7 +116,7 @@ function computeResolutionsToTranscode (videoFileHeight: number) {
   ]
 
   for (const resolution of resolutions) {
-    if (configResolutions[resolution.toString()] === true && videoFileHeight > resolution) {
+    if (configResolutions[resolution + 'p'] === true && videoFileHeight > resolution) {
       resolutionsEnabled.push(resolution)
     }
   }