diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-31 15:09:34 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-31 15:09:34 +0200 |
commit | cf7a61b5a2b68fd966c4a355e37e84b048ed296b (patch) | |
tree | 4f4867344fe6856cb4f6b18856867c6e34171ea2 /server/helpers | |
parent | c487d3033cad9c5e0f85ae49ed3d2a7b6c2711d8 (diff) | |
download | PeerTube-cf7a61b5a2b68fd966c4a355e37e84b048ed296b.tar.gz PeerTube-cf7a61b5a2b68fd966c4a355e37e84b048ed296b.tar.zst PeerTube-cf7a61b5a2b68fd966c4a355e37e84b048ed296b.zip |
Cleanup req files on bad request
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/core-utils.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-captions.ts | 2 | ||||
-rw-r--r-- | server/helpers/utils.ts | 28 |
3 files changed, 29 insertions, 3 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 2951aef1e..884206aad 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts | |||
@@ -58,7 +58,7 @@ function escapeHTML (stringParam) { | |||
58 | '<': '<', | 58 | '<': '<', |
59 | '>': '>', | 59 | '>': '>', |
60 | '"': '"', | 60 | '"': '"', |
61 | "'": ''', | 61 | '\'': ''', |
62 | '/': '/', | 62 | '/': '/', |
63 | '`': '`', | 63 | '`': '`', |
64 | '=': '=' | 64 | '=': '=' |
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index 6a9c6d75c..6b1729f36 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES, VIDEO_MIMETYPE_EXT } from '../../initializers' | 1 | import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES } from '../../initializers' |
2 | import { exists, isFileValid } from './misc' | 2 | import { exists, isFileValid } from './misc' |
3 | import { Response } from 'express' | 3 | import { Response } from 'express' |
4 | import { VideoModel } from '../../models/video/video' | 4 | import { VideoModel } from '../../models/video/video' |
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index cfb427570..7abcec5d7 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -6,11 +6,35 @@ import { CONFIG } from '../initializers' | |||
6 | import { UserModel } from '../models/account/user' | 6 | import { UserModel } from '../models/account/user' |
7 | import { ActorModel } from '../models/activitypub/actor' | 7 | import { ActorModel } from '../models/activitypub/actor' |
8 | import { ApplicationModel } from '../models/application/application' | 8 | import { ApplicationModel } from '../models/application/application' |
9 | import { pseudoRandomBytesPromise } from './core-utils' | 9 | import { pseudoRandomBytesPromise, unlinkPromise } from './core-utils' |
10 | import { logger } from './logger' | 10 | import { logger } from './logger' |
11 | import { isArray } from './custom-validators/misc' | ||
11 | 12 | ||
12 | const isCidr = require('is-cidr') | 13 | const isCidr = require('is-cidr') |
13 | 14 | ||
15 | function cleanUpReqFiles (req: { files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[] }) { | ||
16 | const files = req.files | ||
17 | |||
18 | if (!files) return | ||
19 | |||
20 | if (isArray(files)) { | ||
21 | (files as Express.Multer.File[]).forEach(f => deleteFileAsync(f.path)) | ||
22 | return | ||
23 | } | ||
24 | |||
25 | for (const key of Object.keys(files)) { | ||
26 | const file = files[key] | ||
27 | |||
28 | if (isArray(file)) file.forEach(f => deleteFileAsync(f.path)) | ||
29 | else deleteFileAsync(file.path) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | function deleteFileAsync (path: string) { | ||
34 | unlinkPromise(path) | ||
35 | .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err })) | ||
36 | } | ||
37 | |||
14 | async function generateRandomString (size: number) { | 38 | async function generateRandomString (size: number) { |
15 | const raw = await pseudoRandomBytesPromise(size) | 39 | const raw = await pseudoRandomBytesPromise(size) |
16 | 40 | ||
@@ -162,6 +186,8 @@ type SortType = { sortModel: any, sortValue: string } | |||
162 | // --------------------------------------------------------------------------- | 186 | // --------------------------------------------------------------------------- |
163 | 187 | ||
164 | export { | 188 | export { |
189 | cleanUpReqFiles, | ||
190 | deleteFileAsync, | ||
165 | generateRandomString, | 191 | generateRandomString, |
166 | getFormattedObjects, | 192 | getFormattedObjects, |
167 | isSignupAllowed, | 193 | isSignupAllowed, |