From 2cb03dc1f4e01ba491c36caff30c33fe9c5bad89 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Apr 2021 17:01:35 +0200 Subject: Add banners support --- server/helpers/middlewares/video-channels.ts | 7 +++---- server/helpers/middlewares/videos.ts | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'server/helpers/middlewares') diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts index 05499bb74..e6eab65a2 100644 --- a/server/helpers/middlewares/video-channels.ts +++ b/server/helpers/middlewares/video-channels.ts @@ -1,7 +1,7 @@ import * as express from 'express' -import { VideoChannelModel } from '../../models/video/video-channel' -import { MChannelAccountDefault } from '@server/types/models' +import { MChannelBannerAccountDefault } from '@server/types/models' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { VideoChannelModel } from '../../models/video/video-channel' async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) @@ -29,11 +29,10 @@ export { doesVideoChannelNameWithHostExist } -function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) { +function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) { if (!videoChannel) { res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Video channel not found' }) - .end() return false } diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts index c5eb0607a..403cae092 100644 --- a/server/helpers/middlewares/videos.ts +++ b/server/helpers/middlewares/videos.ts @@ -66,25 +66,24 @@ async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | st } async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAccountId, res: Response) { - if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { - const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) - if (videoChannel === null) { - res.status(HttpStatusCode.BAD_REQUEST_400) - .json({ error: 'Unknown video `video channel` on this instance.' }) - .end() + const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) - return false - } + if (videoChannel === null) { + res.status(HttpStatusCode.BAD_REQUEST_400) + .json({ error: 'Unknown video "video channel" for this instance.' }) + return false + } + + // Don't check account id if the user can update any video + if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { res.locals.videoChannel = videoChannel return true } - const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) - if (videoChannel === null) { + if (videoChannel.Account.id !== user.Account.id) { res.status(HttpStatusCode.BAD_REQUEST_400) - .json({ error: 'Unknown video `video channel` for this account.' }) - .end() + .json({ error: 'Unknown video "video channel" for this account.' }) return false } -- cgit v1.2.3