diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/index.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 8 | ||||
-rw-r--r-- | server/middlewares/validators/videos.ts | 16 | ||||
-rw-r--r-- | server/models/video/tag.ts | 2 |
5 files changed, 20 insertions, 14 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index c07430e6c..bcf1eaee6 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -244,7 +244,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi | |||
244 | 244 | ||
245 | video.VideoFiles = [ videoFile ] | 245 | video.VideoFiles = [ videoFile ] |
246 | 246 | ||
247 | if (videoInfo.tags) { | 247 | if (videoInfo.tags !== undefined) { |
248 | const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t) | 248 | const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t) |
249 | 249 | ||
250 | await video.$set('Tags', tagInstances, sequelizeOptions) | 250 | await video.$set('Tags', tagInstances, sequelizeOptions) |
@@ -332,7 +332,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
332 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) | 332 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) |
333 | 333 | ||
334 | // Video tags update? | 334 | // Video tags update? |
335 | if (videoInfoToUpdate.tags) { | 335 | if (videoInfoToUpdate.tags !== undefined) { |
336 | const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t) | 336 | const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t) |
337 | 337 | ||
338 | await videoInstanceUpdated.$set('Tags', tagInstances, sequelizeOptions) | 338 | await videoInstanceUpdated.$set('Tags', tagInstances, sequelizeOptions) |
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 275482fa1..254b4db6c 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -35,7 +35,7 @@ function toIntOrNull (value: string) { | |||
35 | return validator.toInt(value) | 35 | return validator.toInt(value) |
36 | } | 36 | } |
37 | 37 | ||
38 | function toStringOrNull (value: string) { | 38 | function toValueOrNull (value: string) { |
39 | if (value === 'null') return null | 39 | if (value === 'null') return null |
40 | 40 | ||
41 | return value | 41 | return value |
@@ -73,7 +73,7 @@ export { | |||
73 | isUUIDValid, | 73 | isUUIDValid, |
74 | isIdOrUUIDValid, | 74 | isIdOrUUIDValid, |
75 | isDateValid, | 75 | isDateValid, |
76 | toStringOrNull, | 76 | toValueOrNull, |
77 | isBooleanValid, | 77 | isBooleanValid, |
78 | toIntOrNull, | 78 | toIntOrNull, |
79 | isFileValid | 79 | isFileValid |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index c35db49ac..002324fe0 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -57,9 +57,11 @@ function isVideoTagValid (tag: string) { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | function isVideoTagsValid (tags: string[]) { | 59 | function isVideoTagsValid (tags: string[]) { |
60 | return isArray(tags) && | 60 | return tags === null || ( |
61 | validator.isInt(tags.length.toString(), VIDEOS_CONSTRAINTS_FIELDS.TAGS) && | 61 | isArray(tags) && |
62 | tags.every(tag => isVideoTagValid(tag)) | 62 | validator.isInt(tags.length.toString(), VIDEOS_CONSTRAINTS_FIELDS.TAGS) && |
63 | tags.every(tag => isVideoTagValid(tag)) | ||
64 | ) | ||
63 | } | 65 | } |
64 | 66 | ||
65 | function isVideoAbuseReasonValid (value: string) { | 67 | function isVideoAbuseReasonValid (value: string) { |
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index aa2afb068..dd0246a63 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { UserRight, VideoPrivacy } from '../../../shared' | 4 | import { UserRight, VideoPrivacy } from '../../../shared' |
5 | import { isBooleanValid, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntOrNull, toStringOrNull } from '../../helpers/custom-validators/misc' | 5 | import { isBooleanValid, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntOrNull, toValueOrNull } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
7 | isVideoAbuseReasonValid, | 7 | isVideoAbuseReasonValid, |
8 | isVideoCategoryValid, | 8 | isVideoCategoryValid, |
@@ -52,21 +52,22 @@ const videosAddValidator = [ | |||
52 | .custom(isVideoLicenceValid).withMessage('Should have a valid licence'), | 52 | .custom(isVideoLicenceValid).withMessage('Should have a valid licence'), |
53 | body('language') | 53 | body('language') |
54 | .optional() | 54 | .optional() |
55 | .customSanitizer(toStringOrNull) | 55 | .customSanitizer(toValueOrNull) |
56 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 56 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), |
57 | body('nsfw') | 57 | body('nsfw') |
58 | .toBoolean() | 58 | .toBoolean() |
59 | .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), | 59 | .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), |
60 | body('description') | 60 | body('description') |
61 | .optional() | 61 | .optional() |
62 | .customSanitizer(toStringOrNull) | 62 | .customSanitizer(toValueOrNull) |
63 | .custom(isVideoDescriptionValid).withMessage('Should have a valid description'), | 63 | .custom(isVideoDescriptionValid).withMessage('Should have a valid description'), |
64 | body('support') | 64 | body('support') |
65 | .optional() | 65 | .optional() |
66 | .customSanitizer(toStringOrNull) | 66 | .customSanitizer(toValueOrNull) |
67 | .custom(isVideoSupportValid).withMessage('Should have a valid support text'), | 67 | .custom(isVideoSupportValid).withMessage('Should have a valid support text'), |
68 | body('tags') | 68 | body('tags') |
69 | .optional() | 69 | .optional() |
70 | .customSanitizer(toValueOrNull) | ||
70 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), | 71 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), |
71 | body('commentsEnabled') | 72 | body('commentsEnabled') |
72 | .toBoolean() | 73 | .toBoolean() |
@@ -142,7 +143,7 @@ const videosUpdateValidator = [ | |||
142 | .custom(isVideoLicenceValid).withMessage('Should have a valid licence'), | 143 | .custom(isVideoLicenceValid).withMessage('Should have a valid licence'), |
143 | body('language') | 144 | body('language') |
144 | .optional() | 145 | .optional() |
145 | .customSanitizer(toStringOrNull) | 146 | .customSanitizer(toValueOrNull) |
146 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), | 147 | .custom(isVideoLanguageValid).withMessage('Should have a valid language'), |
147 | body('nsfw') | 148 | body('nsfw') |
148 | .optional() | 149 | .optional() |
@@ -154,14 +155,15 @@ const videosUpdateValidator = [ | |||
154 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), | 155 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), |
155 | body('description') | 156 | body('description') |
156 | .optional() | 157 | .optional() |
157 | .customSanitizer(toStringOrNull) | 158 | .customSanitizer(toValueOrNull) |
158 | .custom(isVideoDescriptionValid).withMessage('Should have a valid description'), | 159 | .custom(isVideoDescriptionValid).withMessage('Should have a valid description'), |
159 | body('support') | 160 | body('support') |
160 | .optional() | 161 | .optional() |
161 | .customSanitizer(toStringOrNull) | 162 | .customSanitizer(toValueOrNull) |
162 | .custom(isVideoSupportValid).withMessage('Should have a valid support text'), | 163 | .custom(isVideoSupportValid).withMessage('Should have a valid support text'), |
163 | body('tags') | 164 | body('tags') |
164 | .optional() | 165 | .optional() |
166 | .customSanitizer(toValueOrNull) | ||
165 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), | 167 | .custom(isVideoTagsValid).withMessage('Should have correct tags'), |
166 | body('commentsEnabled') | 168 | body('commentsEnabled') |
167 | .optional() | 169 | .optional() |
diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index 0ae74d808..6d79a5575 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts | |||
@@ -37,6 +37,8 @@ export class TagModel extends Model<TagModel> { | |||
37 | Videos: VideoModel[] | 37 | Videos: VideoModel[] |
38 | 38 | ||
39 | static findOrCreateTags (tags: string[], transaction: Transaction) { | 39 | static findOrCreateTags (tags: string[], transaction: Transaction) { |
40 | if (tags === null) return [] | ||
41 | |||
40 | const tasks: Bluebird<TagModel>[] = [] | 42 | const tasks: Bluebird<TagModel>[] = [] |
41 | tags.forEach(tag => { | 43 | tags.forEach(tag => { |
42 | const query = { | 44 | const query = { |