aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/express-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-27 16:12:41 +0200
committerChocobozzz <me@florianbigard.com>2021-05-27 16:12:41 +0200
commit8f608a4cb22ab232cfab20665050764b38bac9c7 (patch)
tree6a6785aae79bf5939ad7b7a50a1bd8031268d2b4 /server/helpers/express-utils.ts
parent030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 (diff)
parentc215e627b575d2c4085ccb222f4ca8d0237b7552 (diff)
downloadPeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.gz
PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.zst
PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.zip
Merge branch 'develop' into shorter-URLs-channels-accounts
Diffstat (limited to 'server/helpers/express-utils.ts')
-rw-r--r--server/helpers/express-utils.ts30
1 files changed, 15 insertions, 15 deletions
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index c0d3f8f32..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 { REMOTE_SCHEME } from '../initializers/constants'
4import { logger } from './logger'
5import { deleteFileAsync, generateRandomString } from './utils'
6import { extname } from 'path' 3import { extname } from 'path'
7import { isArray } from './custom-validators/misc' 4import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
8import { CONFIG } from '../initializers/config' 5import { CONFIG } from '../initializers/config'
6import { REMOTE_SCHEME } from '../initializers/constants'
7import { isArray } from './custom-validators/misc'
8import { logger } from './logger'
9import { deleteFileAndCatch, generateRandomString } from './utils'
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 => deleteFileAsync(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 => deleteFileAsync(f.path)) 47 files.forEach(f => deleteFileAndCatch(f.path))
47 else deleteFileAsync(file.path)
48 } 48 }
49} 49}
50 50