diff options
Diffstat (limited to 'server/helpers/express-utils.ts')
-rw-r--r-- | server/helpers/express-utils.ts | 24 |
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' | |||
3 | import { CONFIG, REMOTE_SCHEME } from '../initializers' | 3 | import { CONFIG, REMOTE_SCHEME } from '../initializers' |
4 | import { logger } from './logger' | 4 | import { logger } from './logger' |
5 | import { User } from '../../shared/models/users' | 5 | import { User } from '../../shared/models/users' |
6 | import { generateRandomString } from './utils' | 6 | import { deleteFileAsync, generateRandomString } from './utils' |
7 | import { extname } from 'path' | 7 | import { extname } from 'path' |
8 | import { isArray } from './custom-validators/misc' | ||
8 | 9 | ||
9 | function buildNSFWFilter (res: express.Response, paramNSFW?: string) { | 10 | function 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 | ||
27 | function 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 | |||
26 | function getHostWithPort (host: string) { | 45 | function 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 | } |