X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fmiddlewares%2Fvideos.ts;fp=server%2Fhelpers%2Fmiddlewares%2Fvideos.ts;h=52b934eb79e98fdde34905fa45db5fc97d1d6b49;hb=76148b27f7501bac061992136852be4303370c8d;hp=403cae0925585a4dacaec0e2a68810d4ee066c83;hpb=5ed25fb76e920dac364cb9ef46f14ec4bd372949;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts index 403cae092..52b934eb7 100644 --- a/server/helpers/middlewares/videos.ts +++ b/server/helpers/middlewares/videos.ts @@ -21,10 +21,10 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi const video = await fetchVideo(id, fetchType, userId) if (video === null) { - res.status(HttpStatusCode.NOT_FOUND_404) - .json({ error: 'Video not found' }) - .end() - + res.fail({ + status: HttpStatusCode.NOT_FOUND_404, + message: 'Video not found' + }) return false } @@ -55,10 +55,10 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | string, res: Response) { if (!await VideoFileModel.doesVideoExistForVideoFile(id, videoIdOrUUID)) { - res.status(HttpStatusCode.NOT_FOUND_404) - .json({ error: 'VideoFile matching Video not found' }) - .end() - + res.fail({ + status: HttpStatusCode.NOT_FOUND_404, + message: 'VideoFile matching Video not found' + }) return false } @@ -69,9 +69,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) if (videoChannel === null) { - res.status(HttpStatusCode.BAD_REQUEST_400) - .json({ error: 'Unknown video "video channel" for this instance.' }) - + res.fail({ message: 'Unknown video "video channel" for this instance.' }) return false } @@ -82,9 +80,9 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc } if (videoChannel.Account.id !== user.Account.id) { - res.status(HttpStatusCode.BAD_REQUEST_400) - .json({ error: 'Unknown video "video channel" for this account.' }) - + res.fail({ + message: 'Unknown video "video channel" for this account.' + }) return false } @@ -95,9 +93,10 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: UserRight, res: Response, onlyOwned = true) { // Retrieve the user who did the request if (onlyOwned && video.isOwned() === false) { - res.status(HttpStatusCode.FORBIDDEN_403) - .json({ error: 'Cannot manage a video of another server.' }) - .end() + res.fail({ + status: HttpStatusCode.FORBIDDEN_403, + message: 'Cannot manage a video of another server.' + }) return false } @@ -106,9 +105,10 @@ function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: // Or if s/he is the video's account const account = video.VideoChannel.Account if (user.hasRight(right) === false && account.userId !== user.id) { - res.status(HttpStatusCode.FORBIDDEN_403) - .json({ error: 'Cannot manage a video of another user.' }) - .end() + res.fail({ + status: HttpStatusCode.FORBIDDEN_403, + message: 'Cannot manage a video of another user.' + }) return false }