diff options
Diffstat (limited to 'server')
34 files changed, 311 insertions, 241 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index 31a2de5ca..be196d2a4 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts | |||
@@ -1,7 +1,4 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { Response } from 'express' | ||
3 | import 'express-validator' | 1 | import 'express-validator' |
4 | import { AccountModel } from '../../models/account/account' | ||
5 | import { isUserDescriptionValid, isUserUsernameValid } from './users' | 2 | import { isUserDescriptionValid, isUserUsernameValid } from './users' |
6 | import { exists } from './misc' | 3 | import { exists } from './misc' |
7 | 4 | ||
@@ -17,47 +14,10 @@ function isAccountDescriptionValid (value: string) { | |||
17 | return isUserDescriptionValid(value) | 14 | return isUserDescriptionValid(value) |
18 | } | 15 | } |
19 | 16 | ||
20 | function doesAccountIdExist (id: number, res: Response, sendNotFound = true) { | ||
21 | const promise = AccountModel.load(id) | ||
22 | |||
23 | return doesAccountExist(promise, res, sendNotFound) | ||
24 | } | ||
25 | |||
26 | function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { | ||
27 | const promise = AccountModel.loadLocalByName(name) | ||
28 | |||
29 | return doesAccountExist(promise, res, sendNotFound) | ||
30 | } | ||
31 | |||
32 | function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { | ||
33 | return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) | ||
34 | } | ||
35 | |||
36 | async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) { | ||
37 | const account = await p | ||
38 | |||
39 | if (!account) { | ||
40 | if (sendNotFound === true) { | ||
41 | res.status(404) | ||
42 | .send({ error: 'Account not found' }) | ||
43 | .end() | ||
44 | } | ||
45 | |||
46 | return false | ||
47 | } | ||
48 | |||
49 | res.locals.account = account | ||
50 | |||
51 | return true | ||
52 | } | ||
53 | |||
54 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
55 | 18 | ||
56 | export { | 19 | export { |
57 | isAccountIdValid, | 20 | isAccountIdValid, |
58 | doesAccountIdExist, | ||
59 | doesLocalAccountNameExist, | ||
60 | isAccountDescriptionValid, | 21 | isAccountDescriptionValid, |
61 | doesAccountNameWithHostExist, | ||
62 | isAccountNameValid | 22 | isAccountNameValid |
63 | } | 23 | } |
diff --git a/server/helpers/custom-validators/video-abuses.ts b/server/helpers/custom-validators/video-abuses.ts index a61dcee1c..e43d12be8 100644 --- a/server/helpers/custom-validators/video-abuses.ts +++ b/server/helpers/custom-validators/video-abuses.ts | |||
@@ -18,25 +18,9 @@ function isVideoAbuseStateValid (value: string) { | |||
18 | return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined | 18 | return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined |
19 | } | 19 | } |
20 | 20 | ||
21 | async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { | ||
22 | const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) | ||
23 | |||
24 | if (videoAbuse === null) { | ||
25 | res.status(404) | ||
26 | .json({ error: 'Video abuse not found' }) | ||
27 | .end() | ||
28 | |||
29 | return false | ||
30 | } | ||
31 | |||
32 | res.locals.videoAbuse = videoAbuse | ||
33 | return true | ||
34 | } | ||
35 | |||
36 | // --------------------------------------------------------------------------- | 21 | // --------------------------------------------------------------------------- |
37 | 22 | ||
38 | export { | 23 | export { |
39 | doesVideoAbuseExist, | ||
40 | isVideoAbuseStateValid, | 24 | isVideoAbuseStateValid, |
41 | isVideoAbuseReasonValid, | 25 | isVideoAbuseReasonValid, |
42 | isVideoAbuseModerationCommentValid | 26 | isVideoAbuseModerationCommentValid |
diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.ts index 3743f7023..9a44332ef 100644 --- a/server/helpers/custom-validators/video-blacklist.ts +++ b/server/helpers/custom-validators/video-blacklist.ts | |||
@@ -1,8 +1,6 @@ | |||
1 | import { Response } from 'express' | ||
2 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
3 | import { exists } from './misc' | 2 | import { exists } from './misc' |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 3 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
5 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' | ||
6 | import { VideoBlacklistType } from '../../../shared/models/videos' | 4 | import { VideoBlacklistType } from '../../../shared/models/videos' |
7 | 5 | ||
8 | const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST | 6 | const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST |
@@ -11,21 +9,6 @@ function isVideoBlacklistReasonValid (value: string) { | |||
11 | return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) | 9 | return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) |
12 | } | 10 | } |
13 | 11 | ||
14 | async function doesVideoBlacklistExist (videoId: number, res: Response) { | ||
15 | const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) | ||
16 | |||
17 | if (videoBlacklist === null) { | ||
18 | res.status(404) | ||
19 | .json({ error: 'Blacklisted video not found' }) | ||
20 | .end() | ||
21 | |||
22 | return false | ||
23 | } | ||
24 | |||
25 | res.locals.videoBlacklist = videoBlacklist | ||
26 | return true | ||
27 | } | ||
28 | |||
29 | function isVideoBlacklistTypeValid (value: any) { | 12 | function isVideoBlacklistTypeValid (value: any) { |
30 | return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined | 13 | return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined |
31 | } | 14 | } |
@@ -34,6 +17,5 @@ function isVideoBlacklistTypeValid (value: any) { | |||
34 | 17 | ||
35 | export { | 18 | export { |
36 | isVideoBlacklistReasonValid, | 19 | isVideoBlacklistReasonValid, |
37 | isVideoBlacklistTypeValid, | 20 | isVideoBlacklistTypeValid |
38 | doesVideoBlacklistExist | ||
39 | } | 21 | } |
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index 3b6569a8a..d06eb3695 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts | |||
@@ -1,8 +1,5 @@ | |||
1 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' | 1 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' |
2 | import { exists, isFileValid } from './misc' | 2 | import { exists, isFileValid } from './misc' |
3 | import { Response } from 'express' | ||
4 | import { VideoModel } from '../../models/video/video' | ||
5 | import { VideoCaptionModel } from '../../models/video/video-caption' | ||
6 | 3 | ||
7 | function isVideoCaptionLanguageValid (value: any) { | 4 | function isVideoCaptionLanguageValid (value: any) { |
8 | return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined | 5 | return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined |
@@ -16,25 +13,9 @@ function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File | |||
16 | return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) | 13 | return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) |
17 | } | 14 | } |
18 | 15 | ||
19 | async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) { | ||
20 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) | ||
21 | |||
22 | if (!videoCaption) { | ||
23 | res.status(404) | ||
24 | .json({ error: 'Video caption not found' }) | ||
25 | .end() | ||
26 | |||
27 | return false | ||
28 | } | ||
29 | |||
30 | res.locals.videoCaption = videoCaption | ||
31 | return true | ||
32 | } | ||
33 | |||
34 | // --------------------------------------------------------------------------- | 16 | // --------------------------------------------------------------------------- |
35 | 17 | ||
36 | export { | 18 | export { |
37 | isVideoCaptionFile, | 19 | isVideoCaptionFile, |
38 | isVideoCaptionLanguageValid, | 20 | isVideoCaptionLanguageValid |
39 | doesVideoCaptionExist | ||
40 | } | 21 | } |
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index f818ce8f1..0471f6ec4 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts | |||
@@ -20,33 +20,12 @@ function isVideoChannelSupportValid (value: string) { | |||
20 | return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) | 20 | return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) |
21 | } | 21 | } |
22 | 22 | ||
23 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { | ||
24 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) | ||
25 | |||
26 | return processVideoChannelExist(videoChannel, res) | ||
27 | } | ||
28 | |||
29 | async function doesVideoChannelIdExist (id: number, res: express.Response) { | ||
30 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) | ||
31 | |||
32 | return processVideoChannelExist(videoChannel, res) | ||
33 | } | ||
34 | |||
35 | async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { | ||
36 | const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) | ||
37 | |||
38 | return processVideoChannelExist(videoChannel, res) | ||
39 | } | ||
40 | |||
41 | // --------------------------------------------------------------------------- | 23 | // --------------------------------------------------------------------------- |
42 | 24 | ||
43 | export { | 25 | export { |
44 | doesVideoChannelNameWithHostExist, | ||
45 | doesLocalVideoChannelNameExist, | ||
46 | isVideoChannelDescriptionValid, | 26 | isVideoChannelDescriptionValid, |
47 | isVideoChannelNameValid, | 27 | isVideoChannelNameValid, |
48 | isVideoChannelSupportValid, | 28 | isVideoChannelSupportValid, |
49 | doesVideoChannelIdExist | ||
50 | } | 29 | } |
51 | 30 | ||
52 | function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { | 31 | function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { |
diff --git a/server/helpers/custom-validators/video-playlists.ts b/server/helpers/custom-validators/video-playlists.ts index 2fe426560..60125dcda 100644 --- a/server/helpers/custom-validators/video-playlists.ts +++ b/server/helpers/custom-validators/video-playlists.ts | |||
@@ -26,27 +26,9 @@ function isVideoPlaylistTypeValid (value: any) { | |||
26 | return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined | 26 | return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined |
27 | } | 27 | } |
28 | 28 | ||
29 | async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { | ||
30 | const videoPlaylist = fetchType === 'summary' | ||
31 | ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) | ||
32 | : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) | ||
33 | |||
34 | if (!videoPlaylist) { | ||
35 | res.status(404) | ||
36 | .json({ error: 'Video playlist not found' }) | ||
37 | .end() | ||
38 | |||
39 | return false | ||
40 | } | ||
41 | |||
42 | res.locals.videoPlaylist = videoPlaylist | ||
43 | return true | ||
44 | } | ||
45 | |||
46 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
47 | 30 | ||
48 | export { | 31 | export { |
49 | doesVideoPlaylistExist, | ||
50 | isVideoPlaylistNameValid, | 32 | isVideoPlaylistNameValid, |
51 | isVideoPlaylistDescriptionValid, | 33 | isVideoPlaylistDescriptionValid, |
52 | isVideoPlaylistPrivacyValid, | 34 | isVideoPlaylistPrivacyValid, |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 214db17a1..157e1a8e3 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -15,10 +15,8 @@ import { | |||
15 | } from '../../initializers/constants' | 15 | } from '../../initializers/constants' |
16 | import { VideoModel } from '../../models/video/video' | 16 | import { VideoModel } from '../../models/video/video' |
17 | import { exists, isArray, isDateValid, isFileValid } from './misc' | 17 | import { exists, isArray, isDateValid, isFileValid } from './misc' |
18 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
19 | import { UserModel } from '../../models/account/user' | 18 | import { UserModel } from '../../models/account/user' |
20 | import * as magnetUtil from 'magnet-uri' | 19 | import * as magnetUtil from 'magnet-uri' |
21 | import { fetchVideo, VideoFetchType } from '../video' | ||
22 | 20 | ||
23 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 21 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
24 | 22 | ||
@@ -143,79 +141,10 @@ function isVideoMagnetUriValid (value: string) { | |||
143 | return parsed && isVideoFileInfoHashValid(parsed.infoHash) | 141 | return parsed && isVideoFileInfoHashValid(parsed.infoHash) |
144 | } | 142 | } |
145 | 143 | ||
146 | function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: UserRight, res: Response) { | ||
147 | // Retrieve the user who did the request | ||
148 | if (video.isOwned() === false) { | ||
149 | res.status(403) | ||
150 | .json({ error: 'Cannot manage a video of another server.' }) | ||
151 | .end() | ||
152 | return false | ||
153 | } | ||
154 | |||
155 | // Check if the user can delete the video | ||
156 | // The user can delete it if he has the right | ||
157 | // Or if s/he is the video's account | ||
158 | const account = video.VideoChannel.Account | ||
159 | if (user.hasRight(right) === false && account.userId !== user.id) { | ||
160 | res.status(403) | ||
161 | .json({ error: 'Cannot manage a video of another user.' }) | ||
162 | .end() | ||
163 | return false | ||
164 | } | ||
165 | |||
166 | return true | ||
167 | } | ||
168 | |||
169 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { | ||
170 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined | ||
171 | |||
172 | const video = await fetchVideo(id, fetchType, userId) | ||
173 | |||
174 | if (video === null) { | ||
175 | res.status(404) | ||
176 | .json({ error: 'Video not found' }) | ||
177 | .end() | ||
178 | |||
179 | return false | ||
180 | } | ||
181 | |||
182 | if (fetchType !== 'none') res.locals.video = video | ||
183 | return true | ||
184 | } | ||
185 | |||
186 | async function doesVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { | ||
187 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { | ||
188 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) | ||
189 | if (videoChannel === null) { | ||
190 | res.status(400) | ||
191 | .json({ error: 'Unknown video `video channel` on this instance.' }) | ||
192 | .end() | ||
193 | |||
194 | return false | ||
195 | } | ||
196 | |||
197 | res.locals.videoChannel = videoChannel | ||
198 | return true | ||
199 | } | ||
200 | |||
201 | const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) | ||
202 | if (videoChannel === null) { | ||
203 | res.status(400) | ||
204 | .json({ error: 'Unknown video `video channel` for this account.' }) | ||
205 | .end() | ||
206 | |||
207 | return false | ||
208 | } | ||
209 | |||
210 | res.locals.videoChannel = videoChannel | ||
211 | return true | ||
212 | } | ||
213 | |||
214 | // --------------------------------------------------------------------------- | 144 | // --------------------------------------------------------------------------- |
215 | 145 | ||
216 | export { | 146 | export { |
217 | isVideoCategoryValid, | 147 | isVideoCategoryValid, |
218 | checkUserCanManageVideo, | ||
219 | isVideoLicenceValid, | 148 | isVideoLicenceValid, |
220 | isVideoLanguageValid, | 149 | isVideoLanguageValid, |
221 | isVideoTruncatedDescriptionValid, | 150 | isVideoTruncatedDescriptionValid, |
@@ -237,9 +166,7 @@ export { | |||
237 | isVideoPrivacyValid, | 166 | isVideoPrivacyValid, |
238 | isVideoFileResolutionValid, | 167 | isVideoFileResolutionValid, |
239 | isVideoFileSizeValid, | 168 | isVideoFileSizeValid, |
240 | doesVideoExist, | ||
241 | isVideoImage, | 169 | isVideoImage, |
242 | doesVideoChannelOfAccountExist, | ||
243 | isVideoSupportValid, | 170 | isVideoSupportValid, |
244 | isVideoFilterValid | 171 | isVideoFilterValid |
245 | } | 172 | } |
diff --git a/server/helpers/middlewares/accounts.ts b/server/helpers/middlewares/accounts.ts new file mode 100644 index 000000000..791022b97 --- /dev/null +++ b/server/helpers/middlewares/accounts.ts | |||
@@ -0,0 +1,46 @@ | |||
1 | import { Response } from 'express' | ||
2 | import { AccountModel } from '../../models/account/account' | ||
3 | import * as Bluebird from 'bluebird' | ||
4 | |||
5 | function doesAccountIdExist (id: number, res: Response, sendNotFound = true) { | ||
6 | const promise = AccountModel.load(id) | ||
7 | |||
8 | return doesAccountExist(promise, res, sendNotFound) | ||
9 | } | ||
10 | |||
11 | function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { | ||
12 | const promise = AccountModel.loadLocalByName(name) | ||
13 | |||
14 | return doesAccountExist(promise, res, sendNotFound) | ||
15 | } | ||
16 | |||
17 | function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { | ||
18 | return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) | ||
19 | } | ||
20 | |||
21 | async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) { | ||
22 | const account = await p | ||
23 | |||
24 | if (!account) { | ||
25 | if (sendNotFound === true) { | ||
26 | res.status(404) | ||
27 | .send({ error: 'Account not found' }) | ||
28 | .end() | ||
29 | } | ||
30 | |||
31 | return false | ||
32 | } | ||
33 | |||
34 | res.locals.account = account | ||
35 | |||
36 | return true | ||
37 | } | ||
38 | |||
39 | // --------------------------------------------------------------------------- | ||
40 | |||
41 | export { | ||
42 | doesAccountIdExist, | ||
43 | doesLocalAccountNameExist, | ||
44 | doesAccountNameWithHostExist, | ||
45 | doesAccountExist | ||
46 | } | ||
diff --git a/server/helpers/middlewares/index.ts b/server/helpers/middlewares/index.ts new file mode 100644 index 000000000..f91aeaa12 --- /dev/null +++ b/server/helpers/middlewares/index.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | export * from './accounts' | ||
2 | export * from './video-abuses' | ||
3 | export * from './video-blacklists' | ||
4 | export * from './video-captions' | ||
5 | export * from './video-channels' | ||
6 | export * from './video-playlists' | ||
7 | export * from './videos' | ||
diff --git a/server/helpers/middlewares/video-abuses.ts b/server/helpers/middlewares/video-abuses.ts new file mode 100644 index 000000000..b23f1f021 --- /dev/null +++ b/server/helpers/middlewares/video-abuses.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import * as express from 'express' | ||
2 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
3 | |||
4 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { | ||
5 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) | ||
6 | |||
7 | return processVideoChannelExist(videoChannel, res) | ||
8 | } | ||
9 | |||
10 | async function doesVideoChannelIdExist (id: number, res: express.Response) { | ||
11 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) | ||
12 | |||
13 | return processVideoChannelExist(videoChannel, res) | ||
14 | } | ||
15 | |||
16 | async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { | ||
17 | const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) | ||
18 | |||
19 | return processVideoChannelExist(videoChannel, res) | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | export { | ||
25 | doesLocalVideoChannelNameExist, | ||
26 | doesVideoChannelIdExist, | ||
27 | doesVideoChannelNameWithHostExist | ||
28 | } | ||
29 | |||
30 | function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { | ||
31 | if (!videoChannel) { | ||
32 | res.status(404) | ||
33 | .json({ error: 'Video channel not found' }) | ||
34 | .end() | ||
35 | |||
36 | return false | ||
37 | } | ||
38 | |||
39 | res.locals.videoChannel = videoChannel | ||
40 | return true | ||
41 | } | ||
diff --git a/server/helpers/middlewares/video-blacklists.ts b/server/helpers/middlewares/video-blacklists.ts new file mode 100644 index 000000000..c79420a0c --- /dev/null +++ b/server/helpers/middlewares/video-blacklists.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import { Response } from 'express' | ||
2 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' | ||
3 | |||
4 | async function doesVideoBlacklistExist (videoId: number, res: Response) { | ||
5 | const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) | ||
6 | |||
7 | if (videoBlacklist === null) { | ||
8 | res.status(404) | ||
9 | .json({ error: 'Blacklisted video not found' }) | ||
10 | .end() | ||
11 | |||
12 | return false | ||
13 | } | ||
14 | |||
15 | res.locals.videoBlacklist = videoBlacklist | ||
16 | return true | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | doesVideoBlacklistExist | ||
23 | } | ||
diff --git a/server/helpers/middlewares/video-captions.ts b/server/helpers/middlewares/video-captions.ts new file mode 100644 index 000000000..dc3d0144b --- /dev/null +++ b/server/helpers/middlewares/video-captions.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { VideoModel } from '../../models/video/video' | ||
2 | import { Response } from 'express' | ||
3 | import { VideoCaptionModel } from '../../models/video/video-caption' | ||
4 | |||
5 | async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) { | ||
6 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) | ||
7 | |||
8 | if (!videoCaption) { | ||
9 | res.status(404) | ||
10 | .json({ error: 'Video caption not found' }) | ||
11 | .end() | ||
12 | |||
13 | return false | ||
14 | } | ||
15 | |||
16 | res.locals.videoCaption = videoCaption | ||
17 | return true | ||
18 | } | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | export { | ||
23 | doesVideoCaptionExist | ||
24 | } | ||
diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts new file mode 100644 index 000000000..1b573ca37 --- /dev/null +++ b/server/helpers/middlewares/video-channels.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import { Response } from 'express' | ||
2 | import { VideoAbuseModel } from '../../models/video/video-abuse' | ||
3 | |||
4 | async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { | ||
5 | const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) | ||
6 | |||
7 | if (videoAbuse === null) { | ||
8 | res.status(404) | ||
9 | .json({ error: 'Video abuse not found' }) | ||
10 | .end() | ||
11 | |||
12 | return false | ||
13 | } | ||
14 | |||
15 | res.locals.videoAbuse = videoAbuse | ||
16 | return true | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | doesVideoAbuseExist | ||
23 | } | ||
diff --git a/server/helpers/middlewares/video-playlists.ts b/server/helpers/middlewares/video-playlists.ts new file mode 100644 index 000000000..735bf362f --- /dev/null +++ b/server/helpers/middlewares/video-playlists.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import * as express from 'express' | ||
2 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | ||
3 | |||
4 | async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { | ||
5 | const videoPlaylist = fetchType === 'summary' | ||
6 | ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) | ||
7 | : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) | ||
8 | |||
9 | if (!videoPlaylist) { | ||
10 | res.status(404) | ||
11 | .json({ error: 'Video playlist not found' }) | ||
12 | .end() | ||
13 | |||
14 | return false | ||
15 | } | ||
16 | |||
17 | res.locals.videoPlaylist = videoPlaylist | ||
18 | return true | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | export { | ||
24 | doesVideoPlaylistExist | ||
25 | } | ||
diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts new file mode 100644 index 000000000..ceb1058ec --- /dev/null +++ b/server/helpers/middlewares/videos.ts | |||
@@ -0,0 +1,82 @@ | |||
1 | import { Response } from 'express' | ||
2 | import { fetchVideo, VideoFetchType } from '../video' | ||
3 | import { UserModel } from '../../models/account/user' | ||
4 | import { UserRight } from '../../../shared/models/users' | ||
5 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
6 | import { VideoModel } from '../../models/video/video' | ||
7 | |||
8 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { | ||
9 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined | ||
10 | |||
11 | const video = await fetchVideo(id, fetchType, userId) | ||
12 | |||
13 | if (video === null) { | ||
14 | res.status(404) | ||
15 | .json({ error: 'Video not found' }) | ||
16 | .end() | ||
17 | |||
18 | return false | ||
19 | } | ||
20 | |||
21 | if (fetchType !== 'none') res.locals.video = video | ||
22 | return true | ||
23 | } | ||
24 | |||
25 | async function doesVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { | ||
26 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { | ||
27 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) | ||
28 | if (videoChannel === null) { | ||
29 | res.status(400) | ||
30 | .json({ error: 'Unknown video `video channel` on this instance.' }) | ||
31 | .end() | ||
32 | |||
33 | return false | ||
34 | } | ||
35 | |||
36 | res.locals.videoChannel = videoChannel | ||
37 | return true | ||
38 | } | ||
39 | |||
40 | const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) | ||
41 | if (videoChannel === null) { | ||
42 | res.status(400) | ||
43 | .json({ error: 'Unknown video `video channel` for this account.' }) | ||
44 | .end() | ||
45 | |||
46 | return false | ||
47 | } | ||
48 | |||
49 | res.locals.videoChannel = videoChannel | ||
50 | return true | ||
51 | } | ||
52 | |||
53 | function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: UserRight, res: Response) { | ||
54 | // Retrieve the user who did the request | ||
55 | if (video.isOwned() === false) { | ||
56 | res.status(403) | ||
57 | .json({ error: 'Cannot manage a video of another server.' }) | ||
58 | .end() | ||
59 | return false | ||
60 | } | ||
61 | |||
62 | // Check if the user can delete the video | ||
63 | // The user can delete it if he has the right | ||
64 | // Or if s/he is the video's account | ||
65 | const account = video.VideoChannel.Account | ||
66 | if (user.hasRight(right) === false && account.userId !== user.id) { | ||
67 | res.status(403) | ||
68 | .json({ error: 'Cannot manage a video of another user.' }) | ||
69 | .end() | ||
70 | return false | ||
71 | } | ||
72 | |||
73 | return true | ||
74 | } | ||
75 | |||
76 | // --------------------------------------------------------------------------- | ||
77 | |||
78 | export { | ||
79 | doesVideoChannelOfAccountExist, | ||
80 | doesVideoExist, | ||
81 | checkUserCanManageVideo | ||
82 | } | ||
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 1e7897220..44bd7abb5 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts | |||
@@ -12,12 +12,15 @@ import { AccountModel } from '../models/account/account' | |||
12 | import { VideoChannelModel } from '../models/video/video-channel' | 12 | import { VideoChannelModel } from '../models/video/video-channel' |
13 | import * as Bluebird from 'bluebird' | 13 | import * as Bluebird from 'bluebird' |
14 | import { CONFIG } from '../initializers/config' | 14 | import { CONFIG } from '../initializers/config' |
15 | import { logger } from '../helpers/logger' | ||
15 | 16 | ||
16 | export class ClientHtml { | 17 | export class ClientHtml { |
17 | 18 | ||
18 | private static htmlCache: { [ path: string ]: string } = {} | 19 | private static htmlCache: { [ path: string ]: string } = {} |
19 | 20 | ||
20 | static invalidCache () { | 21 | static invalidCache () { |
22 | logger.info('Cleaning HTML cache.') | ||
23 | |||
21 | ClientHtml.htmlCache = {} | 24 | ClientHtml.htmlCache = {} |
22 | } | 25 | } |
23 | 26 | ||
@@ -146,7 +149,7 @@ export class ClientHtml { | |||
146 | 149 | ||
147 | private static async addAsyncPluginCSS (htmlStringPage: string) { | 150 | private static async addAsyncPluginCSS (htmlStringPage: string) { |
148 | const globalCSSContent = await readFile(PLUGIN_GLOBAL_CSS_PATH) | 151 | const globalCSSContent = await readFile(PLUGIN_GLOBAL_CSS_PATH) |
149 | if (!globalCSSContent) return htmlStringPage | 152 | if (globalCSSContent.byteLength === 0) return htmlStringPage |
150 | 153 | ||
151 | const fileHash = sha256(globalCSSContent) | 154 | const fileHash = sha256(globalCSSContent) |
152 | const linkTag = `<link rel="stylesheet" href="/plugins/global.css?hash=${fileHash}" />` | 155 | const linkTag = `<link rel="stylesheet" href="/plugins/global.css?hash=${fileHash}" />` |
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index c0b49c7c7..a87d02c56 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -317,6 +317,8 @@ export class PluginManager implements ServerHook { | |||
317 | // ###################### CSS ###################### | 317 | // ###################### CSS ###################### |
318 | 318 | ||
319 | private resetCSSGlobalFile () { | 319 | private resetCSSGlobalFile () { |
320 | ClientHtml.invalidCache() | ||
321 | |||
320 | return outputFile(PLUGIN_GLOBAL_CSS_PATH, '') | 322 | return outputFile(PLUGIN_GLOBAL_CSS_PATH, '') |
321 | } | 323 | } |
322 | 324 | ||
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 96e120a38..67e4bf8cc 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { isAccountNameValid, doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares' | ||
6 | 7 | ||
7 | const localAccountValidator = [ | 8 | const localAccountValidator = [ |
8 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), | 9 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), |
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index 7c494de78..63d95e9e0 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -2,13 +2,13 @@ import { body, param } from 'express-validator/check' | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | ||
6 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' | 5 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' |
7 | import { isHostValid } from '../../helpers/custom-validators/servers' | 6 | import { isHostValid } from '../../helpers/custom-validators/servers' |
8 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' | 7 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' |
9 | import { ServerModel } from '../../models/server/server' | 8 | import { ServerModel } from '../../models/server/server' |
10 | import { getServerActor } from '../../helpers/utils' | 9 | import { getServerActor } from '../../helpers/utils' |
11 | import { WEBSERVER } from '../../initializers/constants' | 10 | import { WEBSERVER } from '../../initializers/constants' |
11 | import { doesAccountNameWithHostExist } from '../../helpers/middlewares' | ||
12 | 12 | ||
13 | const blockAccountValidator = [ | 13 | const blockAccountValidator = [ |
14 | body('accountName').exists().withMessage('Should have an account name with host'), | 14 | body('accountName').exists().withMessage('Should have an account name with host'), |
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts index dd362619d..fa130121f 100644 --- a/server/middlewares/validators/feeds.ts +++ b/server/middlewares/validators/feeds.ts | |||
@@ -1,12 +1,16 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param, query } from 'express-validator/check' | 2 | import { param, query } from 'express-validator/check' |
3 | import { doesAccountIdExist, doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
5 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
6 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
7 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | 6 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' |
8 | import { doesVideoChannelIdExist, doesVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels' | 7 | import { doesVideoExist } from '../../helpers/middlewares/videos' |
9 | import { doesVideoExist } from '../../helpers/custom-validators/videos' | 8 | import { |
9 | doesAccountIdExist, | ||
10 | doesAccountNameWithHostExist, | ||
11 | doesVideoChannelIdExist, | ||
12 | doesVideoChannelNameWithHostExist | ||
13 | } from '../../helpers/middlewares' | ||
10 | 14 | ||
11 | const videoFeedsValidator = [ | 15 | const videoFeedsValidator = [ |
12 | param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | 16 | param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), |
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index 0bb908d0b..505319980 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts | |||
@@ -3,10 +3,10 @@ import { query } from 'express-validator/check' | |||
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { isTestInstance } from '../../helpers/core-utils' | 4 | import { isTestInstance } from '../../helpers/core-utils' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { doesVideoExist } from '../../helpers/custom-validators/videos' | ||
7 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
8 | import { areValidationErrors } from './utils' | 7 | import { areValidationErrors } from './utils' |
9 | import { WEBSERVER } from '../../initializers/constants' | 8 | import { WEBSERVER } from '../../initializers/constants' |
9 | import { doesVideoExist } from '../../helpers/middlewares' | ||
10 | 10 | ||
11 | const urlShouldStartWith = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' | 11 | const urlShouldStartWith = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' |
12 | const videoWatchRegex = new RegExp('([^/]+)$') | 12 | const videoWatchRegex = new RegExp('([^/]+)$') |
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts index 76cf89c40..edc53a6b2 100644 --- a/server/middlewares/validators/redundancy.ts +++ b/server/middlewares/validators/redundancy.ts | |||
@@ -2,12 +2,12 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param } from 'express-validator/check' |
4 | import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' | 4 | import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' |
5 | import { doesVideoExist } from '../../helpers/custom-validators/videos' | ||
6 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
7 | import { areValidationErrors } from './utils' | 6 | import { areValidationErrors } from './utils' |
8 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | 7 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' |
9 | import { isHostValid } from '../../helpers/custom-validators/servers' | 8 | import { isHostValid } from '../../helpers/custom-validators/servers' |
10 | import { ServerModel } from '../../models/server/server' | 9 | import { ServerModel } from '../../models/server/server' |
10 | import { doesVideoExist } from '../../helpers/middlewares' | ||
11 | 11 | ||
12 | const videoFileRedundancyGetValidator = [ | 12 | const videoFileRedundancyGetValidator = [ |
13 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), | 13 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index a507afc5b..7002de20d 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -13,12 +13,12 @@ import { | |||
13 | isUserNSFWPolicyValid, | 13 | isUserNSFWPolicyValid, |
14 | isUserPasswordValid, | 14 | isUserPasswordValid, |
15 | isUserRoleValid, | 15 | isUserRoleValid, |
16 | isUserUsernameValid, isUserVideoLanguages, | 16 | isUserUsernameValid, |
17 | isUserVideoLanguages, | ||
17 | isUserVideoQuotaDailyValid, | 18 | isUserVideoQuotaDailyValid, |
18 | isUserVideoQuotaValid, | 19 | isUserVideoQuotaValid, |
19 | isUserVideosHistoryEnabledValid | 20 | isUserVideosHistoryEnabledValid |
20 | } from '../../helpers/custom-validators/users' | 21 | } from '../../helpers/custom-validators/users' |
21 | import { doesVideoExist } from '../../helpers/custom-validators/videos' | ||
22 | import { logger } from '../../helpers/logger' | 22 | import { logger } from '../../helpers/logger' |
23 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | 23 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' |
24 | import { Redis } from '../../lib/redis' | 24 | import { Redis } from '../../lib/redis' |
@@ -30,6 +30,7 @@ import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-c | |||
30 | import { UserRegister } from '../../../shared/models/users/user-register.model' | 30 | import { UserRegister } from '../../../shared/models/users/user-register.model' |
31 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | 31 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
32 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | 32 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
33 | import { doesVideoExist } from '../../helpers/middlewares' | ||
33 | 34 | ||
34 | const usersAddValidator = [ | 35 | const usersAddValidator = [ |
35 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), | 36 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), |
diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts index d1910a992..e176e01af 100644 --- a/server/middlewares/validators/videos/video-abuses.ts +++ b/server/middlewares/validators/videos/video-abuses.ts | |||
@@ -2,15 +2,14 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param } from 'express-validator/check' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' | ||
6 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
7 | import { areValidationErrors } from '../utils' | 6 | import { areValidationErrors } from '../utils' |
8 | import { | 7 | import { |
9 | doesVideoAbuseExist, | ||
10 | isVideoAbuseModerationCommentValid, | 8 | isVideoAbuseModerationCommentValid, |
11 | isVideoAbuseReasonValid, | 9 | isVideoAbuseReasonValid, |
12 | isVideoAbuseStateValid | 10 | isVideoAbuseStateValid |
13 | } from '../../../helpers/custom-validators/video-abuses' | 11 | } from '../../../helpers/custom-validators/video-abuses' |
12 | import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' | ||
14 | 13 | ||
15 | const videoAbuseReportValidator = [ | 14 | const videoAbuseReportValidator = [ |
16 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 15 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 1d7ddb2e3..db59427c7 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts | |||
@@ -1,14 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param, query } from 'express-validator/check' | 2 | import { body, param, query } from 'express-validator/check' |
3 | import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
4 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' | ||
5 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
6 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
7 | import { | 6 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' |
8 | doesVideoBlacklistExist, | 7 | import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares' |
9 | isVideoBlacklistReasonValid, | ||
10 | isVideoBlacklistTypeValid | ||
11 | } from '../../../helpers/custom-validators/video-blacklist' | ||
12 | 8 | ||
13 | const videosBlacklistRemoveValidator = [ | 9 | const videosBlacklistRemoveValidator = [ |
14 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 10 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts index d857ac3ec..f8739e27f 100644 --- a/server/middlewares/validators/videos/video-captions.ts +++ b/server/middlewares/validators/videos/video-captions.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from '../utils' | 2 | import { areValidationErrors } from '../utils' |
3 | import { checkUserCanManageVideo, doesVideoExist } from '../../../helpers/custom-validators/videos' | ||
4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
5 | import { body, param } from 'express-validator/check' | 4 | import { body, param } from 'express-validator/check' |
6 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 5 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
7 | import { UserRight } from '../../../../shared' | 6 | import { UserRight } from '../../../../shared' |
8 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
9 | import { doesVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' | 8 | import { isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' |
10 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 9 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
10 | import { checkUserCanManageVideo, doesVideoCaptionExist, doesVideoExist } from '../../../helpers/middlewares' | ||
11 | 11 | ||
12 | const addVideoCaptionValidator = [ | 12 | const addVideoCaptionValidator = [ |
13 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), | 13 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), |
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index f5a59cacb..c1065b898 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -2,8 +2,6 @@ import * as express from 'express' | |||
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { | 4 | import { |
5 | doesLocalVideoChannelNameExist, | ||
6 | doesVideoChannelNameWithHostExist, | ||
7 | isVideoChannelDescriptionValid, | 5 | isVideoChannelDescriptionValid, |
8 | isVideoChannelNameValid, | 6 | isVideoChannelNameValid, |
9 | isVideoChannelSupportValid | 7 | isVideoChannelSupportValid |
@@ -15,6 +13,7 @@ import { areValidationErrors } from '../utils' | |||
15 | import { isActorPreferredUsernameValid } from '../../../helpers/custom-validators/activitypub/actor' | 13 | import { isActorPreferredUsernameValid } from '../../../helpers/custom-validators/activitypub/actor' |
16 | import { ActorModel } from '../../../models/activitypub/actor' | 14 | import { ActorModel } from '../../../models/activitypub/actor' |
17 | import { isBooleanValid } from '../../../helpers/custom-validators/misc' | 15 | import { isBooleanValid } from '../../../helpers/custom-validators/misc' |
16 | import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../../../helpers/middlewares' | ||
18 | 17 | ||
19 | const videoChannelsAddValidator = [ | 18 | const videoChannelsAddValidator = [ |
20 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 19 | body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), |
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 6b8e2f318..1e3e42833 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts | |||
@@ -3,7 +3,6 @@ import { body, param } from 'express-validator/check' | |||
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' | 5 | import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' |
6 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' | ||
7 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
8 | import { UserModel } from '../../../models/account/user' | 7 | import { UserModel } from '../../../models/account/user' |
9 | import { VideoModel } from '../../../models/video/video' | 8 | import { VideoModel } from '../../../models/video/video' |
@@ -11,6 +10,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' | |||
11 | import { areValidationErrors } from '../utils' | 10 | import { areValidationErrors } from '../utils' |
12 | import { Hooks } from '../../../lib/plugins/hooks' | 11 | import { Hooks } from '../../../lib/plugins/hooks' |
13 | import { isLocalVideoThreadAccepted, isLocalVideoCommentReplyAccepted, AcceptResult } from '../../../lib/moderation' | 12 | import { isLocalVideoThreadAccepted, isLocalVideoCommentReplyAccepted, AcceptResult } from '../../../lib/moderation' |
13 | import { doesVideoExist } from '../../../helpers/middlewares' | ||
14 | 14 | ||
15 | const listVideoCommentThreadsValidator = [ | 15 | const listVideoCommentThreadsValidator = [ |
16 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | 16 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 452084a7c..8b0dd8960 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -6,9 +6,10 @@ import { areValidationErrors } from '../utils' | |||
6 | import { getCommonVideoEditAttributes } from './videos' | 6 | import { getCommonVideoEditAttributes } from './videos' |
7 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' | 7 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' |
8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
9 | import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' | 9 | import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' |
10 | import { CONFIG } from '../../../initializers/config' | 10 | import { CONFIG } from '../../../initializers/config' |
11 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 11 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
12 | import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' | ||
12 | 13 | ||
13 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | 14 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ |
14 | body('channelId') | 15 | body('channelId') |
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 9c88dd291..638122a2e 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts | |||
@@ -4,11 +4,10 @@ import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../.. | |||
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { UserModel } from '../../../models/account/user' | 5 | import { UserModel } from '../../../models/account/user' |
6 | import { areValidationErrors } from '../utils' | 6 | import { areValidationErrors } from '../utils' |
7 | import { doesVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' | 7 | import { isVideoImage } from '../../../helpers/custom-validators/videos' |
8 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 8 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' | 9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' |
10 | import { | 10 | import { |
11 | doesVideoPlaylistExist, | ||
12 | isVideoPlaylistDescriptionValid, | 11 | isVideoPlaylistDescriptionValid, |
13 | isVideoPlaylistNameValid, | 12 | isVideoPlaylistNameValid, |
14 | isVideoPlaylistPrivacyValid, | 13 | isVideoPlaylistPrivacyValid, |
@@ -17,11 +16,11 @@ import { | |||
17 | } from '../../../helpers/custom-validators/video-playlists' | 16 | } from '../../../helpers/custom-validators/video-playlists' |
18 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | 17 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
19 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 18 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
20 | import { doesVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels' | ||
21 | import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' | 19 | import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' |
22 | import { authenticatePromiseIfNeeded } from '../../oauth' | 20 | import { authenticatePromiseIfNeeded } from '../../oauth' |
23 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | 21 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
24 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' | 22 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' |
23 | import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist } from '../../../helpers/middlewares' | ||
25 | 24 | ||
26 | const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ | 25 | const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ |
27 | body('displayName') | 26 | body('displayName') |
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 204b4a78d..5bb3f4a51 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts | |||
@@ -3,12 +3,13 @@ import 'express-validator' | |||
3 | import { body, param, query } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
5 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' | 5 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' |
6 | import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' | 6 | import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' |
7 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
8 | import { areValidationErrors } from '../utils' | 8 | import { areValidationErrors } from '../utils' |
9 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 9 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
10 | import { VideoRateType } from '../../../../shared/models/videos' | 10 | import { VideoRateType } from '../../../../shared/models/videos' |
11 | import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' | 11 | import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' |
12 | import { doesVideoExist } from '../../../helpers/middlewares' | ||
12 | 13 | ||
13 | const videoUpdateRateValidator = [ | 14 | const videoUpdateRateValidator = [ |
14 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 15 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index d5cbdb03e..6f4a1f3e0 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts | |||
@@ -2,10 +2,10 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { param } from 'express-validator/check' | 3 | import { param } from 'express-validator/check' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' | ||
6 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
7 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
8 | import { areValidationErrors } from '../utils' | 7 | import { areValidationErrors } from '../utils' |
8 | import { doesVideoExist } from '../../../helpers/middlewares' | ||
9 | 9 | ||
10 | const videosShareValidator = [ | 10 | const videosShareValidator = [ |
11 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 11 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index a3a800d14..a0b530c75 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { body, param } from 'express-validator/check' | 1 | import { body, param } from 'express-validator/check' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
4 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' | ||
5 | import { areValidationErrors } from '../utils' | 4 | import { areValidationErrors } from '../utils' |
6 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { doesVideoExist } from '../../../helpers/middlewares' | ||
7 | 7 | ||
8 | const videoWatchingValidator = [ | 8 | const videoWatchingValidator = [ |
9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 5593ede64..8f5e5c95c 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -13,9 +13,6 @@ import { | |||
13 | toValueOrNull | 13 | toValueOrNull |
14 | } from '../../../helpers/custom-validators/misc' | 14 | } from '../../../helpers/custom-validators/misc' |
15 | import { | 15 | import { |
16 | checkUserCanManageVideo, | ||
17 | doesVideoChannelOfAccountExist, | ||
18 | doesVideoExist, | ||
19 | isScheduleVideoUpdatePrivacyValid, | 16 | isScheduleVideoUpdatePrivacyValid, |
20 | isVideoCategoryValid, | 17 | isVideoCategoryValid, |
21 | isVideoDescriptionValid, | 18 | isVideoDescriptionValid, |
@@ -33,7 +30,7 @@ import { | |||
33 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' | 30 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' |
34 | import { logger } from '../../../helpers/logger' | 31 | import { logger } from '../../../helpers/logger' |
35 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 32 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
36 | import { authenticate, authenticatePromiseIfNeeded } from '../../oauth' | 33 | import { authenticatePromiseIfNeeded } from '../../oauth' |
37 | import { areValidationErrors } from '../utils' | 34 | import { areValidationErrors } from '../utils' |
38 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 35 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
39 | import { VideoModel } from '../../../models/video/video' | 36 | import { VideoModel } from '../../../models/video/video' |
@@ -46,6 +43,7 @@ import { getServerActor } from '../../../helpers/utils' | |||
46 | import { CONFIG } from '../../../initializers/config' | 43 | import { CONFIG } from '../../../initializers/config' |
47 | import { isLocalVideoAccepted } from '../../../lib/moderation' | 44 | import { isLocalVideoAccepted } from '../../../lib/moderation' |
48 | import { Hooks } from '../../../lib/plugins/hooks' | 45 | import { Hooks } from '../../../lib/plugins/hooks' |
46 | import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '../../../helpers/middlewares' | ||
49 | 47 | ||
50 | const videosAddValidator = getCommonVideoEditAttributes().concat([ | 48 | const videosAddValidator = getCommonVideoEditAttributes().concat([ |
51 | body('videofile') | 49 | body('videofile') |