diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-19 09:26:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-03-19 09:26:50 +0100 |
commit | 0f6acda11681de90d38dd18669863c6e270851ee (patch) | |
tree | b3b28e00d539645f5a810202dc8afada289e7b2e /server/helpers/custom-validators | |
parent | 9a18a6252071cf21b18f82a24bb63078abb75bc1 (diff) | |
download | PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.tar.gz PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.tar.zst PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.zip |
Does exist
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/accounts.ts | 21 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-abuses.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-blacklist.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-captions.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 12 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-imports.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-playlists.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 8 |
8 files changed, 30 insertions, 31 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index aad04fe93..146c7708e 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts | |||
@@ -5,7 +5,6 @@ import * as validator from 'validator' | |||
5 | import { AccountModel } from '../../models/account/account' | 5 | import { AccountModel } from '../../models/account/account' |
6 | import { isUserDescriptionValid, isUserUsernameValid } from './users' | 6 | import { isUserDescriptionValid, isUserUsernameValid } from './users' |
7 | import { exists } from './misc' | 7 | import { exists } from './misc' |
8 | import { CONFIG } from '../../initializers' | ||
9 | 8 | ||
10 | function isAccountNameValid (value: string) { | 9 | function isAccountNameValid (value: string) { |
11 | return isUserUsernameValid(value) | 10 | return isUserUsernameValid(value) |
@@ -19,7 +18,7 @@ function isAccountDescriptionValid (value: string) { | |||
19 | return isUserDescriptionValid(value) | 18 | return isUserDescriptionValid(value) |
20 | } | 19 | } |
21 | 20 | ||
22 | function isAccountIdExist (id: number | string, res: Response, sendNotFound = true) { | 21 | function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { |
23 | let promise: Bluebird<AccountModel> | 22 | let promise: Bluebird<AccountModel> |
24 | 23 | ||
25 | if (validator.isInt('' + id)) { | 24 | if (validator.isInt('' + id)) { |
@@ -28,20 +27,20 @@ function isAccountIdExist (id: number | string, res: Response, sendNotFound = tr | |||
28 | promise = AccountModel.loadByUUID('' + id) | 27 | promise = AccountModel.loadByUUID('' + id) |
29 | } | 28 | } |
30 | 29 | ||
31 | return isAccountExist(promise, res, sendNotFound) | 30 | return doesAccountExist(promise, res, sendNotFound) |
32 | } | 31 | } |
33 | 32 | ||
34 | function isLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { | 33 | function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { |
35 | const promise = AccountModel.loadLocalByName(name) | 34 | const promise = AccountModel.loadLocalByName(name) |
36 | 35 | ||
37 | return isAccountExist(promise, res, sendNotFound) | 36 | return doesAccountExist(promise, res, sendNotFound) |
38 | } | 37 | } |
39 | 38 | ||
40 | function isAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { | 39 | function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { |
41 | return isAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) | 40 | return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) |
42 | } | 41 | } |
43 | 42 | ||
44 | async function isAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) { | 43 | async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) { |
45 | const account = await p | 44 | const account = await p |
46 | 45 | ||
47 | if (!account) { | 46 | if (!account) { |
@@ -63,9 +62,9 @@ async function isAccountExist (p: Bluebird<AccountModel>, res: Response, sendNot | |||
63 | 62 | ||
64 | export { | 63 | export { |
65 | isAccountIdValid, | 64 | isAccountIdValid, |
66 | isAccountIdExist, | 65 | doesAccountIdExist, |
67 | isLocalAccountNameExist, | 66 | doesLocalAccountNameExist, |
68 | isAccountDescriptionValid, | 67 | isAccountDescriptionValid, |
69 | isAccountNameWithHostExist, | 68 | doesAccountNameWithHostExist, |
70 | isAccountNameValid | 69 | isAccountNameValid |
71 | } | 70 | } |
diff --git a/server/helpers/custom-validators/video-abuses.ts b/server/helpers/custom-validators/video-abuses.ts index 290efb149..71500fde5 100644 --- a/server/helpers/custom-validators/video-abuses.ts +++ b/server/helpers/custom-validators/video-abuses.ts | |||
@@ -18,7 +18,7 @@ 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 isVideoAbuseExist (abuseId: number, videoId: number, res: Response) { | 21 | async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { |
22 | const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) | 22 | const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) |
23 | 23 | ||
24 | if (videoAbuse === null) { | 24 | if (videoAbuse === null) { |
@@ -36,7 +36,7 @@ async function isVideoAbuseExist (abuseId: number, videoId: number, res: Respons | |||
36 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |
37 | 37 | ||
38 | export { | 38 | export { |
39 | isVideoAbuseExist, | 39 | doesVideoAbuseExist, |
40 | isVideoAbuseStateValid, | 40 | isVideoAbuseStateValid, |
41 | isVideoAbuseReasonValid, | 41 | isVideoAbuseReasonValid, |
42 | isVideoAbuseModerationCommentValid | 42 | isVideoAbuseModerationCommentValid |
diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.ts index b36b08d8b..25f908228 100644 --- a/server/helpers/custom-validators/video-blacklist.ts +++ b/server/helpers/custom-validators/video-blacklist.ts | |||
@@ -9,7 +9,7 @@ function isVideoBlacklistReasonValid (value: string) { | |||
9 | return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) | 9 | return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) |
10 | } | 10 | } |
11 | 11 | ||
12 | async function isVideoBlacklistExist (videoId: number, res: Response) { | 12 | async function doesVideoBlacklistExist (videoId: number, res: Response) { |
13 | const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) | 13 | const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) |
14 | 14 | ||
15 | if (videoBlacklist === null) { | 15 | if (videoBlacklist === null) { |
@@ -28,5 +28,5 @@ async function isVideoBlacklistExist (videoId: number, res: Response) { | |||
28 | 28 | ||
29 | export { | 29 | export { |
30 | isVideoBlacklistReasonValid, | 30 | isVideoBlacklistReasonValid, |
31 | isVideoBlacklistExist | 31 | doesVideoBlacklistExist |
32 | } | 32 | } |
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index b33d90e18..8bd139003 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts | |||
@@ -16,7 +16,7 @@ function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File | |||
16 | return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) | 16 | return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) |
17 | } | 17 | } |
18 | 18 | ||
19 | async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) { | 19 | async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) { |
20 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) | 20 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) |
21 | 21 | ||
22 | if (!videoCaption) { | 22 | if (!videoCaption) { |
@@ -36,5 +36,5 @@ async function isVideoCaptionExist (video: VideoModel, language: string, res: Re | |||
36 | export { | 36 | export { |
37 | isVideoCaptionFile, | 37 | isVideoCaptionFile, |
38 | isVideoCaptionLanguageValid, | 38 | isVideoCaptionLanguageValid, |
39 | isVideoCaptionExist | 39 | doesVideoCaptionExist |
40 | } | 40 | } |
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index 3792bbdcc..fad7a9bcf 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts | |||
@@ -20,13 +20,13 @@ 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 isLocalVideoChannelNameExist (name: string, res: express.Response) { | 23 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { |
24 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) | 24 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) |
25 | 25 | ||
26 | return processVideoChannelExist(videoChannel, res) | 26 | return processVideoChannelExist(videoChannel, res) |
27 | } | 27 | } |
28 | 28 | ||
29 | async function isVideoChannelIdExist (id: number | string, res: express.Response) { | 29 | async function doesVideoChannelIdExist (id: number | string, res: express.Response) { |
30 | let videoChannel: VideoChannelModel | 30 | let videoChannel: VideoChannelModel |
31 | if (validator.isInt('' + id)) { | 31 | if (validator.isInt('' + id)) { |
32 | videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) | 32 | videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) |
@@ -37,7 +37,7 @@ async function isVideoChannelIdExist (id: number | string, res: express.Response | |||
37 | return processVideoChannelExist(videoChannel, res) | 37 | return processVideoChannelExist(videoChannel, res) |
38 | } | 38 | } |
39 | 39 | ||
40 | async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { | 40 | async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { |
41 | const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) | 41 | const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) |
42 | 42 | ||
43 | return processVideoChannelExist(videoChannel, res) | 43 | return processVideoChannelExist(videoChannel, res) |
@@ -46,12 +46,12 @@ async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: exp | |||
46 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
47 | 47 | ||
48 | export { | 48 | export { |
49 | isVideoChannelNameWithHostExist, | 49 | doesVideoChannelNameWithHostExist, |
50 | isLocalVideoChannelNameExist, | 50 | doesLocalVideoChannelNameExist, |
51 | isVideoChannelDescriptionValid, | 51 | isVideoChannelDescriptionValid, |
52 | isVideoChannelNameValid, | 52 | isVideoChannelNameValid, |
53 | isVideoChannelSupportValid, | 53 | isVideoChannelSupportValid, |
54 | isVideoChannelIdExist | 54 | doesVideoChannelIdExist |
55 | } | 55 | } |
56 | 56 | ||
57 | function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { | 57 | function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { |
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index ce9e9193c..14db9b534 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts | |||
@@ -30,7 +30,7 @@ function isVideoImportTorrentFile (files: { [ fieldname: string ]: Express.Multe | |||
30 | return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true) | 30 | return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true) |
31 | } | 31 | } |
32 | 32 | ||
33 | async function isVideoImportExist (id: number, res: express.Response) { | 33 | async function doesVideoImportExist (id: number, res: express.Response) { |
34 | const videoImport = await VideoImportModel.loadAndPopulateVideo(id) | 34 | const videoImport = await VideoImportModel.loadAndPopulateVideo(id) |
35 | 35 | ||
36 | if (!videoImport) { | 36 | if (!videoImport) { |
@@ -50,6 +50,6 @@ async function isVideoImportExist (id: number, res: express.Response) { | |||
50 | export { | 50 | export { |
51 | isVideoImportStateValid, | 51 | isVideoImportStateValid, |
52 | isVideoImportTargetUrlValid, | 52 | isVideoImportTargetUrlValid, |
53 | isVideoImportExist, | 53 | doesVideoImportExist, |
54 | isVideoImportTorrentFile | 54 | isVideoImportTorrentFile |
55 | } | 55 | } |
diff --git a/server/helpers/custom-validators/video-playlists.ts b/server/helpers/custom-validators/video-playlists.ts index e0eb423d7..c962c5532 100644 --- a/server/helpers/custom-validators/video-playlists.ts +++ b/server/helpers/custom-validators/video-playlists.ts | |||
@@ -26,7 +26,7 @@ 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 isVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { | 29 | async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { |
30 | const videoPlaylist = fetchType === 'summary' | 30 | const videoPlaylist = fetchType === 'summary' |
31 | ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) | 31 | ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) |
32 | : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) | 32 | : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) |
@@ -46,7 +46,7 @@ async function isVideoPlaylistExist (id: number | string, res: express.Response, | |||
46 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
47 | 47 | ||
48 | export { | 48 | export { |
49 | isVideoPlaylistExist, | 49 | doesVideoPlaylistExist, |
50 | isVideoPlaylistNameValid, | 50 | isVideoPlaylistNameValid, |
51 | isVideoPlaylistDescriptionValid, | 51 | isVideoPlaylistDescriptionValid, |
52 | isVideoPlaylistPrivacyValid, | 52 | isVideoPlaylistPrivacyValid, |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index d00d24c4c..dd9d62d24 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -165,7 +165,7 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use | |||
165 | return true | 165 | return true |
166 | } | 166 | } |
167 | 167 | ||
168 | async function isVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { | 168 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { |
169 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined | 169 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined |
170 | 170 | ||
171 | const video = await fetchVideo(id, fetchType, userId) | 171 | const video = await fetchVideo(id, fetchType, userId) |
@@ -182,7 +182,7 @@ async function isVideoExist (id: number | string, res: Response, fetchType: Vide | |||
182 | return true | 182 | return true |
183 | } | 183 | } |
184 | 184 | ||
185 | async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { | 185 | async function doesVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { |
186 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { | 186 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { |
187 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) | 187 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) |
188 | if (videoChannel === null) { | 188 | if (videoChannel === null) { |
@@ -236,9 +236,9 @@ export { | |||
236 | isVideoPrivacyValid, | 236 | isVideoPrivacyValid, |
237 | isVideoFileResolutionValid, | 237 | isVideoFileResolutionValid, |
238 | isVideoFileSizeValid, | 238 | isVideoFileSizeValid, |
239 | isVideoExist, | 239 | doesVideoExist, |
240 | isVideoImage, | 240 | isVideoImage, |
241 | isVideoChannelOfAccountExist, | 241 | doesVideoChannelOfAccountExist, |
242 | isVideoSupportValid, | 242 | isVideoSupportValid, |
243 | isVideoFilterValid | 243 | isVideoFilterValid |
244 | } | 244 | } |