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.ts24
1 files changed, 22 insertions, 2 deletions
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index b3cc40848..1d7bee87e 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -3,8 +3,9 @@ import * as multer from 'multer'
3import { CONFIG, REMOTE_SCHEME } from '../initializers' 3import { CONFIG, REMOTE_SCHEME } from '../initializers'
4import { logger } from './logger' 4import { logger } from './logger'
5import { User } from '../../shared/models/users' 5import { User } from '../../shared/models/users'
6import { generateRandomString } from './utils' 6import { deleteFileAsync, generateRandomString } from './utils'
7import { extname } from 'path' 7import { extname } from 'path'
8import { isArray } from './custom-validators/misc'
8 9
9function buildNSFWFilter (res: express.Response, paramNSFW?: string) { 10function buildNSFWFilter (res: express.Response, paramNSFW?: string) {
10 if (paramNSFW === 'true') return true 11 if (paramNSFW === 'true') return true
@@ -23,6 +24,24 @@ function buildNSFWFilter (res: express.Response, paramNSFW?: string) {
23 return null 24 return null
24} 25}
25 26
27function cleanUpReqFiles (req: { files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[] }) {
28 const files = req.files
29
30 if (!files) return
31
32 if (isArray(files)) {
33 (files as Express.Multer.File[]).forEach(f => deleteFileAsync(f.path))
34 return
35 }
36
37 for (const key of Object.keys(files)) {
38 const file = files[ key ]
39
40 if (isArray(file)) file.forEach(f => deleteFileAsync(f.path))
41 else deleteFileAsync(file.path)
42 }
43}
44
26function getHostWithPort (host: string) { 45function getHostWithPort (host: string) {
27 const splitted = host.split(':') 46 const splitted = host.split(':')
28 47
@@ -82,5 +101,6 @@ export {
82 buildNSFWFilter, 101 buildNSFWFilter,
83 getHostWithPort, 102 getHostWithPort,
84 badRequest, 103 badRequest,
85 createReqFiles 104 createReqFiles,
105 cleanUpReqFiles
86} 106}