diff options
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 338c96582..f4c1c8b07 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -17,6 +17,7 @@ import { VideoModel } from '../../models/video/video' | |||
17 | import { exists, isArray, isFileValid } from './misc' | 17 | import { exists, isArray, isFileValid } from './misc' |
18 | import { VideoChannelModel } from '../../models/video/video-channel' | 18 | import { VideoChannelModel } from '../../models/video/video-channel' |
19 | import { UserModel } from '../../models/account/user' | 19 | import { UserModel } from '../../models/account/user' |
20 | import * as magnetUtil from 'magnet-uri' | ||
20 | 21 | ||
21 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 22 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
22 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | 23 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES |
@@ -126,6 +127,13 @@ function isVideoFileSizeValid (value: string) { | |||
126 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) | 127 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) |
127 | } | 128 | } |
128 | 129 | ||
130 | function isVideoMagnetUriValid (value: string) { | ||
131 | if (!exists(value)) return false | ||
132 | |||
133 | const parsed = magnetUtil.decode(value) | ||
134 | return parsed && isVideoFileInfoHashValid(parsed.infoHash) | ||
135 | } | ||
136 | |||
129 | function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: UserRight, res: Response) { | 137 | function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: UserRight, res: Response) { |
130 | // Retrieve the user who did the request | 138 | // Retrieve the user who did the request |
131 | if (video.isOwned() === false) { | 139 | if (video.isOwned() === false) { |
@@ -214,6 +222,7 @@ export { | |||
214 | isScheduleVideoUpdatePrivacyValid, | 222 | isScheduleVideoUpdatePrivacyValid, |
215 | isVideoAbuseReasonValid, | 223 | isVideoAbuseReasonValid, |
216 | isVideoFile, | 224 | isVideoFile, |
225 | isVideoMagnetUriValid, | ||
217 | isVideoStateValid, | 226 | isVideoStateValid, |
218 | isVideoViewsValid, | 227 | isVideoViewsValid, |
219 | isVideoRatingTypeValid, | 228 | isVideoRatingTypeValid, |