aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/misc.ts2
-rw-r--r--server/helpers/express-utils.ts28
2 files changed, 15 insertions, 15 deletions
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts
index fd3b45804..229e9f03c 100644
--- a/server/helpers/custom-validators/misc.ts
+++ b/server/helpers/custom-validators/misc.ts
@@ -14,7 +14,7 @@ function isSafePath (p: string) {
14 }) 14 })
15} 15}
16 16
17function isArray (value: any) { 17function isArray (value: any): value is any[] {
18 return Array.isArray(value) 18 return Array.isArray(value)
19} 19}
20 20
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index ede22a3cc..010c6961a 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 { extname } from 'path'
4import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
5import { CONFIG } from '../initializers/config'
3import { REMOTE_SCHEME } from '../initializers/constants' 6import { REMOTE_SCHEME } from '../initializers/constants'
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,21 @@ 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 (
34 const files = req.files 34 req: { files: { [fieldname: string]: Express.Multer.File[] } | Express.Multer.File[] }
35 35) {
36 if (!files) return 36 const filesObject = req.files
37 if (!filesObject) return
37 38
38 if (isArray(files)) { 39 if (isArray(filesObject)) {
39 (files as Express.Multer.File[]).forEach(f => deleteFileAndCatch(f.path)) 40 filesObject.forEach(f => deleteFileAndCatch(f.path))
40 return 41 return
41 } 42 }
42 43
43 for (const key of Object.keys(files)) { 44 for (const key of Object.keys(filesObject)) {
44 const file = files[key] 45 const files = filesObject[key]
45 46
46 if (isArray(file)) file.forEach(f => deleteFileAndCatch(f.path)) 47 files.forEach(f => deleteFileAndCatch(f.path))
47 else deleteFileAndCatch(file.path)
48 } 48 }
49} 49}
50 50