aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
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/helpers/custom-validators
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/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/video-comments.ts13
-rw-r--r--server/helpers/custom-validators/video-imports.ts3
-rw-r--r--server/helpers/custom-validators/video-ownership.ts5
3 files changed, 12 insertions, 9 deletions
diff --git a/server/helpers/custom-validators/video-comments.ts b/server/helpers/custom-validators/video-comments.ts
index 455ff4241..8d3ce580e 100644
--- a/server/helpers/custom-validators/video-comments.ts
+++ b/server/helpers/custom-validators/video-comments.ts
@@ -3,6 +3,7 @@ import validator from 'validator'
3import { VideoCommentModel } from '@server/models/video/video-comment' 3import { VideoCommentModel } from '@server/models/video/video-comment'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { MVideoId } from '@server/types/models' 5import { MVideoId } from '@server/types/models'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
6 7
7const VIDEO_COMMENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_COMMENTS 8const VIDEO_COMMENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_COMMENTS
8 9
@@ -15,7 +16,7 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide
15 const videoComment = await VideoCommentModel.loadById(id) 16 const videoComment = await VideoCommentModel.loadById(id)
16 17
17 if (!videoComment) { 18 if (!videoComment) {
18 res.status(404) 19 res.status(HttpStatusCode.NOT_FOUND_404)
19 .json({ error: 'Video comment thread not found' }) 20 .json({ error: 'Video comment thread not found' })
20 .end() 21 .end()
21 22
@@ -23,7 +24,7 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide
23 } 24 }
24 25
25 if (videoComment.videoId !== video.id) { 26 if (videoComment.videoId !== video.id) {
26 res.status(400) 27 res.status(HttpStatusCode.BAD_REQUEST_400)
27 .json({ error: 'Video comment is not associated to this video.' }) 28 .json({ error: 'Video comment is not associated to this video.' })
28 .end() 29 .end()
29 30
@@ -31,7 +32,7 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide
31 } 32 }
32 33
33 if (videoComment.inReplyToCommentId !== null) { 34 if (videoComment.inReplyToCommentId !== null) {
34 res.status(400) 35 res.status(HttpStatusCode.BAD_REQUEST_400)
35 .json({ error: 'Video comment is not a thread.' }) 36 .json({ error: 'Video comment is not a thread.' })
36 .end() 37 .end()
37 38
@@ -47,7 +48,7 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r
47 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) 48 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
48 49
49 if (!videoComment) { 50 if (!videoComment) {
50 res.status(404) 51 res.status(HttpStatusCode.NOT_FOUND_404)
51 .json({ error: 'Video comment thread not found' }) 52 .json({ error: 'Video comment thread not found' })
52 .end() 53 .end()
53 54
@@ -55,7 +56,7 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r
55 } 56 }
56 57
57 if (videoComment.videoId !== video.id) { 58 if (videoComment.videoId !== video.id) {
58 res.status(400) 59 res.status(HttpStatusCode.BAD_REQUEST_400)
59 .json({ error: 'Video comment is not associated to this video.' }) 60 .json({ error: 'Video comment is not associated to this video.' })
60 .end() 61 .end()
61 62
@@ -71,7 +72,7 @@ async function doesCommentIdExist (idArg: number | string, res: express.Response
71 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) 72 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
72 73
73 if (!videoComment) { 74 if (!videoComment) {
74 res.status(404) 75 res.status(HttpStatusCode.NOT_FOUND_404)
75 .json({ error: 'Video comment thread not found' }) 76 .json({ error: 'Video comment thread not found' })
76 77
77 return false 78 return false
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts
index 33a1fa8ab..0063d3337 100644
--- a/server/helpers/custom-validators/video-imports.ts
+++ b/server/helpers/custom-validators/video-imports.ts
@@ -4,6 +4,7 @@ import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initia
4import { exists, isFileValid } from './misc' 4import { exists, isFileValid } from './misc'
5import * as express from 'express' 5import * as express from 'express'
6import { VideoImportModel } from '../../models/video/video-import' 6import { VideoImportModel } from '../../models/video/video-import'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7 8
8function isVideoImportTargetUrlValid (url: string) { 9function isVideoImportTargetUrlValid (url: string) {
9 const isURLOptions = { 10 const isURLOptions = {
@@ -35,7 +36,7 @@ async function doesVideoImportExist (id: number, res: express.Response) {
35 const videoImport = await VideoImportModel.loadAndPopulateVideo(id) 36 const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
36 37
37 if (!videoImport) { 38 if (!videoImport) {
38 res.status(404) 39 res.status(HttpStatusCode.NOT_FOUND_404)
39 .json({ error: 'Video import not found' }) 40 .json({ error: 'Video import not found' })
40 .end() 41 .end()
41 42
diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts
index ed5f8cc2f..ee3cebe10 100644
--- a/server/helpers/custom-validators/video-ownership.ts
+++ b/server/helpers/custom-validators/video-ownership.ts
@@ -2,13 +2,14 @@ import { Response } from 'express'
2import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' 2import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership'
3import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' 3import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership'
4import { MUserId } from '@server/types/models' 4import { MUserId } from '@server/types/models'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5 6
6export async function doesChangeVideoOwnershipExist (idArg: number | string, res: Response) { 7export async function doesChangeVideoOwnershipExist (idArg: number | string, res: Response) {
7 const id = parseInt(idArg + '', 10) 8 const id = parseInt(idArg + '', 10)
8 const videoChangeOwnership = await VideoChangeOwnershipModel.load(id) 9 const videoChangeOwnership = await VideoChangeOwnershipModel.load(id)
9 10
10 if (!videoChangeOwnership) { 11 if (!videoChangeOwnership) {
11 res.status(404) 12 res.status(HttpStatusCode.NOT_FOUND_404)
12 .json({ error: 'Video change ownership not found' }) 13 .json({ error: 'Video change ownership not found' })
13 .end() 14 .end()
14 15
@@ -24,7 +25,7 @@ export function checkUserCanTerminateOwnershipChange (user: MUserId, videoChange
24 return true 25 return true
25 } 26 }
26 27
27 res.status(403) 28 res.status(HttpStatusCode.FORBIDDEN_403)
28 .json({ error: 'Cannot terminate an ownership change of another user' }) 29 .json({ error: 'Cannot terminate an ownership change of another user' })
29 .end() 30 .end()
30 return false 31 return false