From 2d53be0267acc49cda46707b885096193a1f4e9c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 7 Dec 2020 14:32:36 +0100 Subject: replace numbers with typed http status codes (#3409) --- .../validators/videos/video-blacklist.ts | 3 ++- .../validators/videos/video-channels.ts | 19 +++++++-------- .../validators/videos/video-comments.ts | 13 ++++++----- .../middlewares/validators/videos/video-imports.ts | 9 ++++---- server/middlewares/validators/videos/video-live.ts | 21 +++++++++-------- .../validators/videos/video-playlists.ts | 27 +++++++++++----------- .../middlewares/validators/videos/video-rates.ts | 3 ++- .../middlewares/validators/videos/video-shares.ts | 3 ++- .../middlewares/validators/videos/video-watch.ts | 3 ++- server/middlewares/validators/videos/videos.ts | 23 +++++++++--------- 10 files changed, 67 insertions(+), 57 deletions(-) (limited to 'server/middlewares/validators/videos') diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 808fefc25..88c788a43 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts @@ -5,6 +5,7 @@ import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../.. import { logger } from '../../../helpers/logger' import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares' import { areValidationErrors } from '../utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videosBlacklistRemoveValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), @@ -39,7 +40,7 @@ const videosBlacklistAddValidator = [ const video = res.locals.videoAll if (req.body.unfederate === true && video.remote === true) { return res - .status(409) + .status(HttpStatusCode.CONFLICT_409) .send({ error: 'You cannot unfederate a remote video.' }) .end() } diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index 2e4e755e7..57ac548b9 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -15,6 +15,7 @@ import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } fro import { ActorModel } from '../../../models/activitypub/actor' import { VideoChannelModel } from '../../../models/video/video-channel' import { areValidationErrors } from '../utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videoChannelsAddValidator = [ body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), @@ -29,7 +30,7 @@ const videoChannelsAddValidator = [ const actor = await ActorModel.loadLocalByName(req.body.name) if (actor) { - res.status(409) + res.status(HttpStatusCode.CONFLICT_409) .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' }) .end() return false @@ -37,7 +38,7 @@ const videoChannelsAddValidator = [ const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) if (count >= VIDEO_CHANNELS.MAX_PER_USER) { - res.status(400) + res.status(HttpStatusCode.BAD_REQUEST_400) .send({ error: `You cannot create more than ${VIDEO_CHANNELS.MAX_PER_USER} channels` }) .end() return false @@ -70,13 +71,13 @@ const videoChannelsUpdateValidator = [ // We need to make additional checks if (res.locals.videoChannel.Actor.isOwned() === false) { - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot update video channel of another server' }) .end() } if (res.locals.videoChannel.Account.userId !== res.locals.oauth.token.User.id) { - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot update video channel of another user' }) .end() } @@ -155,7 +156,7 @@ export { function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAccountDefault, res: express.Response) { if (videoChannel.Actor.isOwned() === false) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot remove video channel of another server.' }) .end() @@ -166,7 +167,7 @@ function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAcco // The user can delete it if s/he is an admin // Or if s/he is the video channel's account if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_CHANNEL) === false && videoChannel.Account.userId !== user.id) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot remove video channel of another user' }) .end() @@ -180,9 +181,9 @@ async function checkVideoChannelIsNotTheLastOne (res: express.Response) { const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) if (count <= 1) { - res.status(409) - .json({ error: 'Cannot remove the last channel of this user' }) - .end() + res.status(HttpStatusCode.CONFLICT_409) + .json({ error: 'Cannot remove the last channel of this user' }) + .end() return false } diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index a3c9febc4..226c9d436 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts @@ -14,6 +14,7 @@ import { AcceptResult, isLocalVideoCommentReplyAccepted, isLocalVideoThreadAccep import { Hooks } from '../../../lib/plugins/hooks' import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' import { areValidationErrors } from '../utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const listVideoCommentsValidator = [ query('isLocal') @@ -154,8 +155,8 @@ export { function isVideoCommentsEnabled (video: MVideo, res: express.Response) { if (video.commentsEnabled !== true) { - res.status(409) - .json({ error: 'Video comments are disabled for this video.' }) + res.status(HttpStatusCode.CONFLICT_409) + .json({ error: 'Video comments are disabled for this video.' }) return false } @@ -165,8 +166,8 @@ function isVideoCommentsEnabled (video: MVideo, res: express.Response) { function checkUserCanDeleteVideoComment (user: MUserAccountUrl, videoComment: MCommentOwnerVideoReply, res: express.Response) { if (videoComment.isDeleted()) { - res.status(409) - .json({ error: 'This comment is already deleted' }) + res.status(HttpStatusCode.CONFLICT_409) + .json({ error: 'This comment is already deleted' }) return false } @@ -178,7 +179,7 @@ function checkUserCanDeleteVideoComment (user: MUserAccountUrl, videoComment: MC videoComment.accountId !== userAccount.id && // Not the comment owner videoComment.Video.VideoChannel.accountId !== userAccount.id // Not the video owner ) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot remove video comment of another user' }) return false @@ -214,7 +215,7 @@ async function isVideoCommentAccepted (req: express.Request, res: express.Respon if (!acceptedResult || acceptedResult.accepted !== true) { logger.info('Refused local comment.', { acceptedResult, acceptParameters }) - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: acceptedResult.errorMessage || 'Refused local comment' }) return false 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' import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' import { areValidationErrors } from '../utils' import { getCommonVideoEditAttributes } from './videos' +import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' const videoImportAddValidator = getCommonVideoEditAttributes().concat([ body('channelId') @@ -44,14 +45,14 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ if (req.body.targetUrl && CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) { cleanUpReqFiles(req) - return res.status(409) + return res.status(HttpStatusCode.CONFLICT_409) .json({ error: 'HTTP import is not enabled on this instance.' }) .end() } if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) { cleanUpReqFiles(req) - return res.status(409) + return res.status(HttpStatusCode.CONFLICT_409) .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' }) .end() } @@ -62,7 +63,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) { cleanUpReqFiles(req) - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' }) .end() } @@ -100,7 +101,7 @@ async function isImportAccepted (req: express.Request, res: express.Response) { if (!acceptedResult || acceptedResult.accepted !== true) { logger.info('Refused to import video.', { acceptedResult, acceptParameters }) - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: acceptedResult.errorMessage || 'Refused to import video' }) return false diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts index 69a14ccb1..3a73e1272 100644 --- a/server/middlewares/validators/videos/video-live.ts +++ b/server/middlewares/validators/videos/video-live.ts @@ -13,6 +13,7 @@ import { getCommonVideoEditAttributes } from './videos' import { VideoModel } from '@server/models/video/video' import { Hooks } from '@server/lib/plugins/hooks' import { isLocalLiveVideoAccepted } from '@server/lib/moderation' +import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' const videoLiveGetValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), @@ -28,7 +29,7 @@ const videoLiveGetValidator = [ if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.GET_ANY_LIVE, res, false)) return const videoLive = await VideoLiveModel.loadByVideoId(res.locals.videoAll.id) - if (!videoLive) return res.sendStatus(404) + if (!videoLive) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) res.locals.videoLive = videoLive @@ -62,21 +63,21 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ if (CONFIG.LIVE.ENABLED !== true) { cleanUpReqFiles(req) - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Live is not enabled on this instance' }) } if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { cleanUpReqFiles(req) - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Saving live replay is not allowed instance' }) } if (req.body.permanentLive && req.body.saveReplay) { cleanUpReqFiles(req) - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Cannot set this live as permanent while saving its replay' }) } @@ -89,7 +90,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ if (totalInstanceLives >= CONFIG.LIVE.MAX_INSTANCE_LIVES) { cleanUpReqFiles(req) - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ code: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED, error: 'Cannot create this live because the max instance lives limit is reached.' @@ -103,7 +104,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ if (totalUserLives >= CONFIG.LIVE.MAX_USER_LIVES) { cleanUpReqFiles(req) - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ code: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED, error: 'Cannot create this live because the max user lives limit is reached.' @@ -129,17 +130,17 @@ const videoLiveUpdateValidator = [ if (areValidationErrors(req, res)) return if (req.body.permanentLive && req.body.saveReplay) { - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Cannot set this live as permanent while saving its replay' }) } if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Saving live replay is not allowed instance' }) } if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) { - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Cannot update a live that has already started' }) } @@ -176,7 +177,7 @@ async function isLiveVideoAccepted (req: express.Request, res: express.Response) if (!acceptedResult || acceptedResult.accepted !== true) { logger.info('Refused local live video.', { acceptedResult, acceptParameters }) - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: acceptedResult.errorMessage || 'Refused local live video' }) return false diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 4647eae44..c7a6f68e3 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts @@ -29,6 +29,7 @@ import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/vid import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../../../helpers/middlewares' import { MVideoPlaylist } from '../../../types/models/video/video-playlist' import { MUserAccountId } from '@server/types/models' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ body('displayName') @@ -44,7 +45,7 @@ const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ if (body.privacy === VideoPlaylistPrivacy.PUBLIC && !body.videoChannelId) { cleanUpReqFiles(req) - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Cannot set "public" a playlist that is not assigned to a channel.' }) } @@ -83,13 +84,13 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([ ) ) { cleanUpReqFiles(req) - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Cannot set "public" a playlist that is not assigned to a channel.' }) } if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) { cleanUpReqFiles(req) - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Cannot update a watch later playlist.' }) } @@ -112,7 +113,7 @@ const videoPlaylistsDeleteValidator = [ const videoPlaylist = getPlaylist(res) if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) { - return res.status(400) + return res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Cannot delete a watch later playlist.' }) } @@ -142,7 +143,7 @@ const videoPlaylistsGetValidator = (fetchType: VideoPlaylistFetchType) => { if (videoPlaylist.privacy === VideoPlaylistPrivacy.UNLISTED) { if (isUUIDValid(req.params.playlistId)) return next() - return res.status(404).end() + return res.status(HttpStatusCode.NOT_FOUND_404).end() } if (videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) { @@ -154,7 +155,7 @@ const videoPlaylistsGetValidator = (fetchType: VideoPlaylistFetchType) => { !user || (videoPlaylist.OwnerAccount.id !== user.Account.id && !user.hasRight(UserRight.UPDATE_ANY_VIDEO_PLAYLIST)) ) { - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot get this private video playlist.' }) } @@ -231,7 +232,7 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [ const videoPlaylistElement = await VideoPlaylistElementModel.loadById(req.params.playlistElementId) if (!videoPlaylistElement) { - res.status(404) + res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Video playlist element not found' }) .end() @@ -261,7 +262,7 @@ const videoPlaylistElementAPGetValidator = [ const videoPlaylistElement = await VideoPlaylistElementModel.loadByPlaylistAndElementIdForAP(playlistId, playlistElementId) if (!videoPlaylistElement) { - res.status(404) + res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Video playlist element not found' }) .end() @@ -269,7 +270,7 @@ const videoPlaylistElementAPGetValidator = [ } if (videoPlaylistElement.VideoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) { - return res.status(403).end() + return res.status(HttpStatusCode.FORBIDDEN_403).end() } res.locals.videoPlaylistElementAP = videoPlaylistElement @@ -305,7 +306,7 @@ const videoPlaylistsReorderVideosValidator = [ const reorderLength: number = req.body.reorderLength if (startPosition >= nextPosition || insertAfterPosition >= nextPosition) { - res.status(400) + res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: `Start position or insert after position exceed the playlist limits (max: ${nextPosition - 1})` }) .end() @@ -313,7 +314,7 @@ const videoPlaylistsReorderVideosValidator = [ } if (reorderLength && reorderLength + startPosition > nextPosition) { - res.status(400) + res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: `Reorder length with this start position exceeds the playlist limits (max: ${nextPosition - startPosition})` }) .end() @@ -399,7 +400,7 @@ function getCommonPlaylistEditAttributes () { function checkUserCanManageVideoPlaylist (user: MUserAccountId, videoPlaylist: MVideoPlaylist, right: UserRight, res: express.Response) { if (videoPlaylist.isOwned() === false) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot manage video playlist of another server.' }) .end() @@ -410,7 +411,7 @@ function checkUserCanManageVideoPlaylist (user: MUserAccountId, videoPlaylist: M // The user can delete it if s/he is an admin // Or if s/he is the video playlist's owner if (user.hasRight(right) === false && videoPlaylist.ownerAccountId !== user.Account.id) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot manage video playlist of another user' }) .end() diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 15a8c7983..7dcba15f1 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts @@ -9,6 +9,7 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat import { VideoRateType } from '../../../../shared/models/videos' import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' import { doesVideoExist } from '../../../helpers/middlewares' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videoUpdateRateValidator = [ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), @@ -36,7 +37,7 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.name, req.params.videoId) if (!rate) { - return res.status(404) + return res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Video rate not found' }) } diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index 20fc96243..f0d8e0c36 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts @@ -5,6 +5,7 @@ import { logger } from '../../../helpers/logger' import { VideoShareModel } from '../../../models/video/video-share' import { areValidationErrors } from '../utils' import { doesVideoExist } from '../../../helpers/middlewares' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videosShareValidator = [ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), @@ -20,7 +21,7 @@ const videosShareValidator = [ const share = await VideoShareModel.load(req.params.actorId, video.id) if (!share) { - return res.status(404) + return res.status(HttpStatusCode.NOT_FOUND_404) .end() } diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index d6ca1d341..29ce0dab6 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts @@ -4,6 +4,7 @@ import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators import { areValidationErrors } from '../utils' import { logger } from '../../../helpers/logger' import { doesVideoExist } from '../../../helpers/middlewares' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videoWatchingValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), @@ -20,7 +21,7 @@ const videoWatchingValidator = [ const user = res.locals.oauth.token.User if (user.videosHistoryEnabled === false) { logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id) - return res.status(409).end() + return res.status(HttpStatusCode.CONFLICT_409).end() } return next() diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index af0072d73..9834f714b 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -51,6 +51,7 @@ import { AccountModel } from '../../../models/account/account' import { VideoModel } from '../../../models/video/video' import { authenticatePromiseIfNeeded } from '../../oauth' import { areValidationErrors } from '../utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const videosAddValidator = getCommonVideoEditAttributes().concat([ body('videofile') @@ -75,7 +76,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) if (await isAbleToUploadVideo(user.id, videoFile.size) === false) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'The user video quota is exceeded with this video.' }) return cleanUpReqFiles(req) @@ -87,7 +88,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ duration = await getDurationFromVideoFile(videoFile.path) } catch (err) { logger.error('Invalid input file in videosAddValidator.', { err }) - res.status(400) + res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Invalid input file.' }) return cleanUpReqFiles(req) @@ -147,7 +148,7 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R const serverActor = await getServerActor() if (await VideoModel.checkVideoHasInstanceFollow(video.id, serverActor.id) === true) return next() - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS, error: 'Cannot get this video regarding follow constraints.', @@ -182,7 +183,7 @@ const videosCustomGetValidator = ( // Only the owner or a user that have blacklist rights can see the video if (!user || !user.canGetVideo(videoAll)) { - return res.status(403) + return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot get this private/internal or blacklisted video.' }) } @@ -197,7 +198,7 @@ const videosCustomGetValidator = ( if (isUUIDValid(req.params.id)) return next() // Don't leak this unlisted video - return res.status(404).end() + return res.status(HttpStatusCode.NOT_FOUND_404).end() } } ] @@ -250,7 +251,7 @@ const videosChangeOwnershipValidator = [ const nextOwner = await AccountModel.loadLocalByName(req.body.username) if (!nextOwner) { - res.status(400) + res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Changing video ownership to a remote account is not supported yet' }) return @@ -276,7 +277,7 @@ const videosTerminateChangeOwnershipValidator = [ const videoChangeOwnership = res.locals.videoChangeOwnership if (videoChangeOwnership.status !== VideoChangeOwnershipStatus.WAITING) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Ownership already accepted or refused' }) return } @@ -294,7 +295,7 @@ const videosAcceptChangeOwnershipValidator = [ const videoChangeOwnership = res.locals.videoChangeOwnership const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size) if (isAble === false) { - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'The user video quota is exceeded with this video.' }) return @@ -433,7 +434,7 @@ const commonVideosFiltersValidator = [ (req.query.filter === 'all-local' || req.query.filter === 'all') && (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false) ) { - res.status(401) + res.status(HttpStatusCode.UNAUTHORIZED_401) .json({ error: 'You are not allowed to see all local videos.' }) return @@ -473,7 +474,7 @@ function areErrorsInScheduleUpdate (req: express.Request, res: express.Response) if (!req.body.scheduleUpdate.updateAt) { logger.warn('Invalid parameters: scheduleUpdate.updateAt is mandatory.') - res.status(400) + res.status(HttpStatusCode.BAD_REQUEST_400) .json({ error: 'Schedule update at is mandatory.' }) return true @@ -498,7 +499,7 @@ async function isVideoAccepted (req: express.Request, res: express.Response, vid if (!acceptedResult || acceptedResult.accepted !== true) { logger.info('Refused local video.', { acceptedResult, acceptParameters }) - res.status(403) + res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: acceptedResult.errorMessage || 'Refused local video' }) return false -- cgit v1.2.3