aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/express-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/express-utils.ts')
-rw-r--r--server/helpers/express-utils.ts28
1 files changed, 13 insertions, 15 deletions
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index ede22a3cc..0ff113274 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -1,13 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as multer from 'multer' 2import * as multer from 'multer'
3import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
4import { CONFIG } from '../initializers/config'
3import { REMOTE_SCHEME } from '../initializers/constants' 5import { REMOTE_SCHEME } from '../initializers/constants'
6import { getLowercaseExtension } from './core-utils'
7import { isArray } from './custom-validators/misc'
4import { logger } from './logger' 8import { logger } from './logger'
5import { deleteFileAndCatch, generateRandomString } from './utils' 9import { deleteFileAndCatch, generateRandomString } from './utils'
6import { extname } from 'path'
7import { isArray } from './custom-validators/misc'
8import { CONFIG } from '../initializers/config'
9import { getExtFromMimetype } from './video' 10import { getExtFromMimetype } from './video'
10import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
11 11
12function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { 12function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
13 if (paramNSFW === 'true') return true 13 if (paramNSFW === 'true') return true
@@ -30,21 +30,19 @@ function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
30 return null 30 return null
31} 31}
32 32
33function cleanUpReqFiles (req: { files: { [fieldname: string]: Express.Multer.File[] } | Express.Multer.File[] }) { 33function cleanUpReqFiles (req: express.Request) {
34 const files = req.files 34 const filesObject = req.files
35 35 if (!filesObject) return
36 if (!files) return
37 36
38 if (isArray(files)) { 37 if (isArray(filesObject)) {
39 (files as Express.Multer.File[]).forEach(f => deleteFileAndCatch(f.path)) 38 filesObject.forEach(f => deleteFileAndCatch(f.path))
40 return 39 return
41 } 40 }
42 41
43 for (const key of Object.keys(files)) { 42 for (const key of Object.keys(filesObject)) {
44 const file = files[key] 43 const files = filesObject[key]
45 44
46 if (isArray(file)) file.forEach(f => deleteFileAndCatch(f.path)) 45 files.forEach(f => deleteFileAndCatch(f.path))
47 else deleteFileAndCatch(file.path)
48 } 46 }
49} 47}
50 48
@@ -79,7 +77,7 @@ function createReqFiles (
79 77
80 filename: async (req, file, cb) => { 78 filename: async (req, file, cb) => {
81 let extension: string 79 let extension: string
82 const fileExtension = extname(file.originalname) 80 const fileExtension = getLowercaseExtension(file.originalname)
83 const extensionFromMimetype = getExtFromMimetype(mimeTypes, file.mimetype) 81 const extensionFromMimetype = getExtFromMimetype(mimeTypes, file.mimetype)
84 82
85 // Take the file extension if we don't understand the mime type 83 // Take the file extension if we don't understand the mime type