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/custom-validators/users.ts | 8 ++++---- server/helpers/middlewares/video-channels.ts | 7 +++---- server/helpers/middlewares/videos.ts | 23 +++++++++++------------ 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index d6e91ad35..85f3634c8 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -1,9 +1,9 @@ +import { values } from 'lodash' import validator from 'validator' import { UserRole } from '../../../shared' +import { isEmailEnabled } from '../../initializers/config' import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' import { exists, isArray, isBooleanValid, isFileValid } from './misc' -import { values } from 'lodash' -import { isEmailEnabled } from '../../initializers/config' const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS @@ -97,12 +97,12 @@ function isUserRoleValid (value: any) { return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined } -const avatarMimeTypes = CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME +const avatarMimeTypes = CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME .map(v => v.replace('.', '')) .join('|') const avatarMimeTypesRegex = `image/(${avatarMimeTypes})` function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { - return isFileValid(files, avatarMimeTypesRegex, 'avatarfile', CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max) + return isFileValid(files, avatarMimeTypesRegex, 'avatarfile', CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max) } // --------------------------------------------------------------------------- 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