aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/blocklist.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/blocklist.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/blocklist.ts')
-rw-r--r--server/middlewares/validators/blocklist.ts9
1 files changed, 5 insertions, 4 deletions
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts
index c24fa9609..f61811a1a 100644
--- a/server/middlewares/validators/blocklist.ts
+++ b/server/middlewares/validators/blocklist.ts
@@ -9,6 +9,7 @@ import { ServerModel } from '../../models/server/server'
9import { WEBSERVER } from '../../initializers/constants' 9import { WEBSERVER } from '../../initializers/constants'
10import { doesAccountNameWithHostExist } from '../../helpers/middlewares' 10import { doesAccountNameWithHostExist } from '../../helpers/middlewares'
11import { getServerActor } from '@server/models/application/application' 11import { getServerActor } from '@server/models/application/application'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
12 13
13const blockAccountValidator = [ 14const blockAccountValidator = [
14 body('accountName').exists().withMessage('Should have an account name with host'), 15 body('accountName').exists().withMessage('Should have an account name with host'),
@@ -23,7 +24,7 @@ const blockAccountValidator = [
23 const accountToBlock = res.locals.account 24 const accountToBlock = res.locals.account
24 25
25 if (user.Account.id === accountToBlock.id) { 26 if (user.Account.id === accountToBlock.id) {
26 res.status(409) 27 res.status(HttpStatusCode.CONFLICT_409)
27 .json({ error: 'You cannot block yourself.' }) 28 .json({ error: 'You cannot block yourself.' })
28 29
29 return 30 return
@@ -78,7 +79,7 @@ const blockServerValidator = [
78 const host: string = req.body.host 79 const host: string = req.body.host
79 80
80 if (host === WEBSERVER.HOST) { 81 if (host === WEBSERVER.HOST) {
81 return res.status(409) 82 return res.status(HttpStatusCode.CONFLICT_409)
82 .json({ error: 'You cannot block your own server.' }) 83 .json({ error: 'You cannot block your own server.' })
83 } 84 }
84 85
@@ -136,7 +137,7 @@ export {
136async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { 137async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) {
137 const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) 138 const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId)
138 if (!accountBlock) { 139 if (!accountBlock) {
139 res.status(404) 140 res.status(HttpStatusCode.NOT_FOUND_404)
140 .json({ error: 'Account block entry not found.' }) 141 .json({ error: 'Account block entry not found.' })
141 142
142 return false 143 return false
@@ -150,7 +151,7 @@ async function doesUnblockAccountExist (accountId: number, targetAccountId: numb
150async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { 151async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) {
151 const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) 152 const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host)
152 if (!serverBlock) { 153 if (!serverBlock) {
153 res.status(404) 154 res.status(HttpStatusCode.NOT_FOUND_404)
154 .json({ error: 'Server block entry not found.' }) 155 .json({ error: 'Server block entry not found.' })
155 156
156 return false 157 return false