aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/misc.ts4
-rw-r--r--server/helpers/custom-validators/videos.ts8
2 files changed, 6 insertions, 6 deletions
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 (
51 files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], 51 files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
52 mimeTypeRegex: string, 52 mimeTypeRegex: string,
53 field: string, 53 field: string,
54 maxSize: number, 54 maxSize: number | null,
55 optional = false 55 optional = false
56) { 56) {
57 // Should have files 57 // Should have files
@@ -69,7 +69,7 @@ function isFileValid (
69 if (!file || !file.originalname) return false 69 if (!file || !file.originalname) return false
70 70
71 // Check size 71 // Check size
72 if (maxSize && file.size > maxSize) return false 72 if ((maxSize !== null) && file.size > maxSize) return false
73 73
74 return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype) 74 return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype)
75} 75}
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
150} 150}
151 151
152async function isVideoExist (id: string, res: Response) { 152async function isVideoExist (id: string, res: Response) {
153 let video: VideoModel 153 let video: VideoModel | null
154 154
155 if (validator.isInt(id)) { 155 if (validator.isInt(id)) {
156 video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) 156 video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id)
@@ -158,7 +158,7 @@ async function isVideoExist (id: string, res: Response) {
158 video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) 158 video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id)
159 } 159 }
160 160
161 if (!video) { 161 if (video && video !== null) {
162 res.status(404) 162 res.status(404)
163 .json({ error: 'Video not found' }) 163 .json({ error: 'Video not found' })
164 .end() 164 .end()
@@ -173,7 +173,7 @@ async function isVideoExist (id: string, res: Response) {
173async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { 173async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
174 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { 174 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
175 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) 175 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
176 if (!videoChannel) { 176 if (videoChannel && videoChannel !== null) {
177 res.status(400) 177 res.status(400)
178 .json({ error: 'Unknown video video channel on this instance.' }) 178 .json({ error: 'Unknown video video channel on this instance.' })
179 .end() 179 .end()
@@ -186,7 +186,7 @@ async function isVideoChannelOfAccountExist (channelId: number, user: UserModel,
186 } 186 }
187 187
188 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) 188 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
189 if (!videoChannel) { 189 if (videoChannel && videoChannel !== null) {
190 res.status(400) 190 res.status(400)
191 .json({ error: 'Unknown video video channel for this account.' }) 191 .json({ error: 'Unknown video video channel for this account.' })
192 .end() 192 .end()