]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/express-utils.ts
Downsample to the closest divisor standard framerate
[github/Chocobozzz/PeerTube.git] / server / helpers / express-utils.ts
index fef2da313e8b164cb43097af2b2ee68b1a9e1719..9bf6d85a87a21f76338090a551cabb425e4dd463 100644 (file)
@@ -1,10 +1,11 @@
 import * as express from 'express'
 import * as multer from 'multer'
-import { CONFIG, REMOTE_SCHEME } from '../initializers'
+import { REMOTE_SCHEME } from '../initializers/constants'
 import { logger } from './logger'
 import { deleteFileAsync, generateRandomString } from './utils'
 import { extname } from 'path'
 import { isArray } from './custom-validators/misc'
+import { CONFIG } from '../initializers/config'
 
 function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
   if (paramNSFW === 'true') return true
@@ -58,7 +59,7 @@ function getHostWithPort (host: string) {
   return host
 }
 
-function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) {
+function badRequest (req: express.Request, res: express.Response) {
   return res.type('json').status(400).end()
 }
 
@@ -73,7 +74,18 @@ function createReqFiles (
     },
 
     filename: async (req, file, cb) => {
-      const extension = mimeTypes[ file.mimetype ] || extname(file.originalname)
+      let extension: string
+      const fileExtension = extname(file.originalname)
+      const extensionFromMimetype = mimeTypes[ file.mimetype ]
+
+      // Take the file extension if we don't understand the mime type
+      // We have the OGG/OGV exception too because firefox sends a bad mime type when sending an OGG file
+      if (fileExtension === '.ogg' || fileExtension === '.ogv' || !extensionFromMimetype) {
+        extension = fileExtension
+      } else {
+        extension = extensionFromMimetype
+      }
+
       let randomString = ''
 
       try {
@@ -105,6 +117,10 @@ function isUserAbleToSearchRemoteURI (res: express.Response) {
     (CONFIG.SEARCH.REMOTE_URI.USERS === true && user !== undefined)
 }
 
+function getCountVideos (req: express.Request) {
+  return req.query.skipCount !== true
+}
+
 // ---------------------------------------------------------------------------
 
 export {
@@ -113,5 +129,6 @@ export {
   isUserAbleToSearchRemoteURI,
   badRequest,
   createReqFiles,
-  cleanUpReqFiles
+  cleanUpReqFiles,
+  getCountVideos
 }