From 0f6acda11681de90d38dd18669863c6e270851ee Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 09:26:50 +0100 Subject: Does exist --- server/helpers/custom-validators/accounts.ts | 21 ++++++++++----------- server/helpers/custom-validators/video-abuses.ts | 4 ++-- server/helpers/custom-validators/video-blacklist.ts | 4 ++-- server/helpers/custom-validators/video-captions.ts | 4 ++-- server/helpers/custom-validators/video-channels.ts | 12 ++++++------ server/helpers/custom-validators/video-imports.ts | 4 ++-- server/helpers/custom-validators/video-playlists.ts | 4 ++-- server/helpers/custom-validators/videos.ts | 8 ++++---- 8 files changed, 30 insertions(+), 31 deletions(-) (limited to 'server/helpers/custom-validators') 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' import { AccountModel } from '../../models/account/account' import { isUserDescriptionValid, isUserUsernameValid } from './users' import { exists } from './misc' -import { CONFIG } from '../../initializers' function isAccountNameValid (value: string) { return isUserUsernameValid(value) @@ -19,7 +18,7 @@ function isAccountDescriptionValid (value: string) { return isUserDescriptionValid(value) } -function isAccountIdExist (id: number | string, res: Response, sendNotFound = true) { +function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { let promise: Bluebird if (validator.isInt('' + id)) { @@ -28,20 +27,20 @@ function isAccountIdExist (id: number | string, res: Response, sendNotFound = tr promise = AccountModel.loadByUUID('' + id) } - return isAccountExist(promise, res, sendNotFound) + return doesAccountExist(promise, res, sendNotFound) } -function isLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { +function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { const promise = AccountModel.loadLocalByName(name) - return isAccountExist(promise, res, sendNotFound) + return doesAccountExist(promise, res, sendNotFound) } -function isAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { - return isAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) +function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { + return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) } -async function isAccountExist (p: Bluebird, res: Response, sendNotFound: boolean) { +async function doesAccountExist (p: Bluebird, res: Response, sendNotFound: boolean) { const account = await p if (!account) { @@ -63,9 +62,9 @@ async function isAccountExist (p: Bluebird, res: Response, sendNot export { isAccountIdValid, - isAccountIdExist, - isLocalAccountNameExist, + doesAccountIdExist, + doesLocalAccountNameExist, isAccountDescriptionValid, - isAccountNameWithHostExist, + doesAccountNameWithHostExist, isAccountNameValid } 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) { return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined } -async function isVideoAbuseExist (abuseId: number, videoId: number, res: Response) { +async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) if (videoAbuse === null) { @@ -36,7 +36,7 @@ async function isVideoAbuseExist (abuseId: number, videoId: number, res: Respons // --------------------------------------------------------------------------- export { - isVideoAbuseExist, + doesVideoAbuseExist, isVideoAbuseStateValid, isVideoAbuseReasonValid, 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) { return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) } -async function isVideoBlacklistExist (videoId: number, res: Response) { +async function doesVideoBlacklistExist (videoId: number, res: Response) { const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) if (videoBlacklist === null) { @@ -28,5 +28,5 @@ async function isVideoBlacklistExist (videoId: number, res: Response) { export { isVideoBlacklistReasonValid, - isVideoBlacklistExist + doesVideoBlacklistExist } 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 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) } -async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) { +async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) { const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) if (!videoCaption) { @@ -36,5 +36,5 @@ async function isVideoCaptionExist (video: VideoModel, language: string, res: Re export { isVideoCaptionFile, isVideoCaptionLanguageValid, - isVideoCaptionExist + doesVideoCaptionExist } 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) { return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) } -async function isLocalVideoChannelNameExist (name: string, res: express.Response) { +async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) return processVideoChannelExist(videoChannel, res) } -async function isVideoChannelIdExist (id: number | string, res: express.Response) { +async function doesVideoChannelIdExist (id: number | string, res: express.Response) { let videoChannel: VideoChannelModel if (validator.isInt('' + id)) { videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) @@ -37,7 +37,7 @@ async function isVideoChannelIdExist (id: number | string, res: express.Response return processVideoChannelExist(videoChannel, res) } -async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { +async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) return processVideoChannelExist(videoChannel, res) @@ -46,12 +46,12 @@ async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: exp // --------------------------------------------------------------------------- export { - isVideoChannelNameWithHostExist, - isLocalVideoChannelNameExist, + doesVideoChannelNameWithHostExist, + doesLocalVideoChannelNameExist, isVideoChannelDescriptionValid, isVideoChannelNameValid, isVideoChannelSupportValid, - isVideoChannelIdExist + doesVideoChannelIdExist } 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 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true) } -async function isVideoImportExist (id: number, res: express.Response) { +async function doesVideoImportExist (id: number, res: express.Response) { const videoImport = await VideoImportModel.loadAndPopulateVideo(id) if (!videoImport) { @@ -50,6 +50,6 @@ async function isVideoImportExist (id: number, res: express.Response) { export { isVideoImportStateValid, isVideoImportTargetUrlValid, - isVideoImportExist, + doesVideoImportExist, isVideoImportTorrentFile } 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) { return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined } -async function isVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { +async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { const videoPlaylist = fetchType === 'summary' ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) @@ -46,7 +46,7 @@ async function isVideoPlaylistExist (id: number | string, res: express.Response, // --------------------------------------------------------------------------- export { - isVideoPlaylistExist, + doesVideoPlaylistExist, isVideoPlaylistNameValid, isVideoPlaylistDescriptionValid, 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 return true } -async function isVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { +async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined const video = await fetchVideo(id, fetchType, userId) @@ -182,7 +182,7 @@ async function isVideoExist (id: number | string, res: Response, fetchType: Vide return true } -async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { +async function doesVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) if (videoChannel === null) { @@ -236,9 +236,9 @@ export { isVideoPrivacyValid, isVideoFileResolutionValid, isVideoFileSizeValid, - isVideoExist, + doesVideoExist, isVideoImage, - isVideoChannelOfAccountExist, + doesVideoChannelOfAccountExist, isVideoSupportValid, isVideoFilterValid } -- cgit v1.2.3