From c1e791bad0b079af67398f6407221e6dcbb573dd Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 25 Jul 2018 22:01:25 +0200 Subject: expliciting type checks and predicates (server only) --- server/helpers/custom-validators/misc.ts | 4 ++-- server/helpers/custom-validators/videos.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 151fc852b..6d10a65a8 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -51,7 +51,7 @@ function isFileValid ( files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], mimeTypeRegex: string, field: string, - maxSize: number, + maxSize: number | null, optional = false ) { // Should have files @@ -69,7 +69,7 @@ function isFileValid ( if (!file || !file.originalname) return false // Check size - if (maxSize && file.size > maxSize) return false + if ((maxSize !== null) && file.size > maxSize) return false return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype) } diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index b5cb126d9..70904af0c 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -150,7 +150,7 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use } async function isVideoExist (id: string, res: Response) { - let video: VideoModel + let video: VideoModel | null if (validator.isInt(id)) { video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) @@ -158,7 +158,7 @@ async function isVideoExist (id: string, res: Response) { video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) } - if (!video) { + if (video && video !== null) { res.status(404) .json({ error: 'Video not found' }) .end() @@ -173,7 +173,7 @@ async function isVideoExist (id: string, res: Response) { async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) - if (!videoChannel) { + if (videoChannel && videoChannel !== null) { res.status(400) .json({ error: 'Unknown video video channel on this instance.' }) .end() @@ -186,7 +186,7 @@ async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, } const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) - if (!videoChannel) { + if (videoChannel && videoChannel !== null) { res.status(400) .json({ error: 'Unknown video video channel for this account.' }) .end() -- cgit v1.2.3