diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/users.ts | 8 | ||||
-rw-r--r-- | server/helpers/middlewares/video-channels.ts | 7 | ||||
-rw-r--r-- | server/helpers/middlewares/videos.ts | 23 |
3 files changed, 18 insertions, 20 deletions
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 @@ | |||
1 | import { values } from 'lodash' | ||
1 | import validator from 'validator' | 2 | import validator from 'validator' |
2 | import { UserRole } from '../../../shared' | 3 | import { UserRole } from '../../../shared' |
4 | import { isEmailEnabled } from '../../initializers/config' | ||
3 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' | 5 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' |
4 | import { exists, isArray, isBooleanValid, isFileValid } from './misc' | 6 | import { exists, isArray, isBooleanValid, isFileValid } from './misc' |
5 | import { values } from 'lodash' | ||
6 | import { isEmailEnabled } from '../../initializers/config' | ||
7 | 7 | ||
8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS | 8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS |
9 | 9 | ||
@@ -97,12 +97,12 @@ function isUserRoleValid (value: any) { | |||
97 | return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined | 97 | return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined |
98 | } | 98 | } |
99 | 99 | ||
100 | const avatarMimeTypes = CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME | 100 | const avatarMimeTypes = CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME |
101 | .map(v => v.replace('.', '')) | 101 | .map(v => v.replace('.', '')) |
102 | .join('|') | 102 | .join('|') |
103 | const avatarMimeTypesRegex = `image/(${avatarMimeTypes})` | 103 | const avatarMimeTypesRegex = `image/(${avatarMimeTypes})` |
104 | function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { | 104 | function isAvatarFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { |
105 | return isFileValid(files, avatarMimeTypesRegex, 'avatarfile', CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max) | 105 | return isFileValid(files, avatarMimeTypesRegex, 'avatarfile', CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max) |
106 | } | 106 | } |
107 | 107 | ||
108 | // --------------------------------------------------------------------------- | 108 | // --------------------------------------------------------------------------- |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoChannelModel } from '../../models/video/video-channel' | 2 | import { MChannelBannerAccountDefault } from '@server/types/models' |
3 | import { MChannelAccountDefault } from '@server/types/models' | ||
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
4 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
5 | 5 | ||
6 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { | 6 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { |
7 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) | 7 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) |
@@ -29,11 +29,10 @@ export { | |||
29 | doesVideoChannelNameWithHostExist | 29 | doesVideoChannelNameWithHostExist |
30 | } | 30 | } |
31 | 31 | ||
32 | function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) { | 32 | function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) { |
33 | if (!videoChannel) { | 33 | if (!videoChannel) { |
34 | res.status(HttpStatusCode.NOT_FOUND_404) | 34 | res.status(HttpStatusCode.NOT_FOUND_404) |
35 | .json({ error: 'Video channel not found' }) | 35 | .json({ error: 'Video channel not found' }) |
36 | .end() | ||
37 | 36 | ||
38 | return false | 37 | return false |
39 | } | 38 | } |
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 | |||
66 | } | 66 | } |
67 | 67 | ||
68 | async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAccountId, res: Response) { | 68 | async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAccountId, res: Response) { |
69 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { | 69 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) |
70 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) | ||
71 | if (videoChannel === null) { | ||
72 | res.status(HttpStatusCode.BAD_REQUEST_400) | ||
73 | .json({ error: 'Unknown video `video channel` on this instance.' }) | ||
74 | .end() | ||
75 | 70 | ||
76 | return false | 71 | if (videoChannel === null) { |
77 | } | 72 | res.status(HttpStatusCode.BAD_REQUEST_400) |
73 | .json({ error: 'Unknown video "video channel" for this instance.' }) | ||
78 | 74 | ||
75 | return false | ||
76 | } | ||
77 | |||
78 | // Don't check account id if the user can update any video | ||
79 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { | ||
79 | res.locals.videoChannel = videoChannel | 80 | res.locals.videoChannel = videoChannel |
80 | return true | 81 | return true |
81 | } | 82 | } |
82 | 83 | ||
83 | const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) | 84 | if (videoChannel.Account.id !== user.Account.id) { |
84 | if (videoChannel === null) { | ||
85 | res.status(HttpStatusCode.BAD_REQUEST_400) | 85 | res.status(HttpStatusCode.BAD_REQUEST_400) |
86 | .json({ error: 'Unknown video `video channel` for this account.' }) | 86 | .json({ error: 'Unknown video "video channel" for this account.' }) |
87 | .end() | ||
88 | 87 | ||
89 | return false | 88 | return false |
90 | } | 89 | } |