aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-31 15:09:34 +0200
committerChocobozzz <me@florianbigard.com>2018-07-31 15:09:34 +0200
commitcf7a61b5a2b68fd966c4a355e37e84b048ed296b (patch)
tree4f4867344fe6856cb4f6b18856867c6e34171ea2 /server/helpers
parentc487d3033cad9c5e0f85ae49ed3d2a7b6c2711d8 (diff)
downloadPeerTube-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.ts2
-rw-r--r--server/helpers/custom-validators/video-captions.ts2
-rw-r--r--server/helpers/utils.ts28
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 '<': '&lt;', 58 '<': '&lt;',
59 '>': '&gt;', 59 '>': '&gt;',
60 '"': '&quot;', 60 '"': '&quot;',
61 "'": '&#39;', 61 '\'': '&#39;',
62 '/': '&#x2F;', 62 '/': '&#x2F;',
63 '`': '&#x60;', 63 '`': '&#x60;',
64 '=': '&#x3D;' 64 '=': '&#x3D;'
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 @@
1import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES, VIDEO_MIMETYPE_EXT } from '../../initializers' 1import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES } from '../../initializers'
2import { exists, isFileValid } from './misc' 2import { exists, isFileValid } from './misc'
3import { Response } from 'express' 3import { Response } from 'express'
4import { VideoModel } from '../../models/video/video' 4import { 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'
6import { UserModel } from '../models/account/user' 6import { UserModel } from '../models/account/user'
7import { ActorModel } from '../models/activitypub/actor' 7import { ActorModel } from '../models/activitypub/actor'
8import { ApplicationModel } from '../models/application/application' 8import { ApplicationModel } from '../models/application/application'
9import { pseudoRandomBytesPromise } from './core-utils' 9import { pseudoRandomBytesPromise, unlinkPromise } from './core-utils'
10import { logger } from './logger' 10import { logger } from './logger'
11import { isArray } from './custom-validators/misc'
11 12
12const isCidr = require('is-cidr') 13const isCidr = require('is-cidr')
13 14
15function 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
33function deleteFileAsync (path: string) {
34 unlinkPromise(path)
35 .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err }))
36}
37
14async function generateRandomString (size: number) { 38async 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
164export { 188export {
189 cleanUpReqFiles,
190 deleteFileAsync,
165 generateRandomString, 191 generateRandomString,
166 getFormattedObjects, 192 getFormattedObjects,
167 isSignupAllowed, 193 isSignupAllowed,