aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos/video-imports.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/middlewares/validators/videos/video-imports.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/middlewares/validators/videos/video-imports.ts')
-rw-r--r--server/middlewares/validators/videos/video-imports.ts9
1 files changed, 5 insertions, 4 deletions
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts
index d69aff118..0d41933a6 100644
--- a/server/middlewares/validators/videos/video-imports.ts
+++ b/server/middlewares/validators/videos/video-imports.ts
@@ -13,6 +13,7 @@ import { CONFIG } from '../../../initializers/config'
13import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 13import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
14import { areValidationErrors } from '../utils' 14import { areValidationErrors } from '../utils'
15import { getCommonVideoEditAttributes } from './videos' 15import { getCommonVideoEditAttributes } from './videos'
16import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
16 17
17const videoImportAddValidator = getCommonVideoEditAttributes().concat([ 18const videoImportAddValidator = getCommonVideoEditAttributes().concat([
18 body('channelId') 19 body('channelId')
@@ -44,14 +45,14 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
44 45
45 if (req.body.targetUrl && CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) { 46 if (req.body.targetUrl && CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) {
46 cleanUpReqFiles(req) 47 cleanUpReqFiles(req)
47 return res.status(409) 48 return res.status(HttpStatusCode.CONFLICT_409)
48 .json({ error: 'HTTP import is not enabled on this instance.' }) 49 .json({ error: 'HTTP import is not enabled on this instance.' })
49 .end() 50 .end()
50 } 51 }
51 52
52 if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) { 53 if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) {
53 cleanUpReqFiles(req) 54 cleanUpReqFiles(req)
54 return res.status(409) 55 return res.status(HttpStatusCode.CONFLICT_409)
55 .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' }) 56 .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' })
56 .end() 57 .end()
57 } 58 }
@@ -62,7 +63,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
62 if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) { 63 if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) {
63 cleanUpReqFiles(req) 64 cleanUpReqFiles(req)
64 65
65 return res.status(400) 66 return res.status(HttpStatusCode.BAD_REQUEST_400)
66 .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' }) 67 .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' })
67 .end() 68 .end()
68 } 69 }
@@ -100,7 +101,7 @@ async function isImportAccepted (req: express.Request, res: express.Response) {
100 101
101 if (!acceptedResult || acceptedResult.accepted !== true) { 102 if (!acceptedResult || acceptedResult.accepted !== true) {
102 logger.info('Refused to import video.', { acceptedResult, acceptParameters }) 103 logger.info('Refused to import video.', { acceptedResult, acceptParameters })
103 res.status(403) 104 res.status(HttpStatusCode.FORBIDDEN_403)
104 .json({ error: acceptedResult.errorMessage || 'Refused to import video' }) 105 .json({ error: acceptedResult.errorMessage || 'Refused to import video' })
105 106
106 return false 107 return false