diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-06 17:13:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-08 09:30:31 +0200 |
commit | ce33919c24e7402d92d81f3cd8e545df52d98240 (patch) | |
tree | 7e131a2f8df649899d0a71294665cf386ffb50d4 /server/helpers/custom-validators | |
parent | 788487140c500abeb69ca44daf3a9e26efa8d36f (diff) | |
download | PeerTube-ce33919c24e7402d92d81f3cd8e545df52d98240.tar.gz PeerTube-ce33919c24e7402d92d81f3cd8e545df52d98240.tar.zst PeerTube-ce33919c24e7402d92d81f3cd8e545df52d98240.zip |
Import magnets with webtorrent
Diffstat (limited to 'server/helpers/custom-validators')
-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, |