aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-11-15 15:06:03 +0100
committerChocobozzz <me@florianbigard.com>2019-11-25 10:59:43 +0100
commitd7a25329f9e607894d29ab342b9cb66638b56dc0 (patch)
tree6cd6bc4f2689f78944238b313c93427423a932ac /server/helpers/custom-validators
parent14981d7331da3f63fe6cfaf020ccb7c910006eaf (diff)
downloadPeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.tar.gz
PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.tar.zst
PeerTube-d7a25329f9e607894d29ab342b9cb66638b56dc0.zip
Add ability to disable webtorrent
In favour of HLS
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts36
1 files changed, 24 insertions, 12 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index 02f914326..a28bebf2d 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -12,6 +12,7 @@ import {
12} from '../videos' 12} from '../videos'
13import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' 13import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
14import { VideoState } from '../../../../shared/models/videos' 14import { VideoState } from '../../../../shared/models/videos'
15import { logger } from '@server/helpers/logger'
15 16
16function sanitizeAndCheckVideoTorrentUpdateActivity (activity: any) { 17function sanitizeAndCheckVideoTorrentUpdateActivity (activity: any) {
17 return isBaseActivityValid(activity, 'Update') && 18 return isBaseActivityValid(activity, 'Update') &&
@@ -30,11 +31,26 @@ function isActivityPubVideoDurationValid (value: string) {
30function sanitizeAndCheckVideoTorrentObject (video: any) { 31function sanitizeAndCheckVideoTorrentObject (video: any) {
31 if (!video || video.type !== 'Video') return false 32 if (!video || video.type !== 'Video') return false
32 33
33 if (!setValidRemoteTags(video)) return false 34 if (!setValidRemoteTags(video)) {
34 if (!setValidRemoteVideoUrls(video)) return false 35 logger.debug('Video has invalid tags', { video })
35 if (!setRemoteVideoTruncatedContent(video)) return false 36 return false
36 if (!setValidAttributedTo(video)) return false 37 }
37 if (!setValidRemoteCaptions(video)) return false 38 if (!setValidRemoteVideoUrls(video)) {
39 logger.debug('Video has invalid urls', { video })
40 return false
41 }
42 if (!setRemoteVideoTruncatedContent(video)) {
43 logger.debug('Video has invalid content', { video })
44 return false
45 }
46 if (!setValidAttributedTo(video)) {
47 logger.debug('Video has invalid attributedTo', { video })
48 return false
49 }
50 if (!setValidRemoteCaptions(video)) {
51 logger.debug('Video has invalid captions', { video })
52 return false
53 }
38 54
39 // Default attributes 55 // Default attributes
40 if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED 56 if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED
@@ -62,25 +78,21 @@ function sanitizeAndCheckVideoTorrentObject (video: any) {
62} 78}
63 79
64function isRemoteVideoUrlValid (url: any) { 80function isRemoteVideoUrlValid (url: any) {
65 // FIXME: Old bug, we used the width to represent the resolution. Remove it in a few release (currently beta.11)
66 if (url.width && !url.height) url.height = url.width
67
68 return url.type === 'Link' && 81 return url.type === 'Link' &&
69 ( 82 (
70 // TODO: remove mimeType (backward compatibility, introduced in v1.1.0) 83 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mediaType) !== -1 &&
71 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mediaType || url.mimeType) !== -1 &&
72 isActivityPubUrlValid(url.href) && 84 isActivityPubUrlValid(url.href) &&
73 validator.isInt(url.height + '', { min: 0 }) && 85 validator.isInt(url.height + '', { min: 0 }) &&
74 validator.isInt(url.size + '', { min: 0 }) && 86 validator.isInt(url.size + '', { min: 0 }) &&
75 (!url.fps || validator.isInt(url.fps + '', { min: -1 })) 87 (!url.fps || validator.isInt(url.fps + '', { min: -1 }))
76 ) || 88 ) ||
77 ( 89 (
78 ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mediaType || url.mimeType) !== -1 && 90 ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mediaType) !== -1 &&
79 isActivityPubUrlValid(url.href) && 91 isActivityPubUrlValid(url.href) &&
80 validator.isInt(url.height + '', { min: 0 }) 92 validator.isInt(url.height + '', { min: 0 })
81 ) || 93 ) ||
82 ( 94 (
83 ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mediaType || url.mimeType) !== -1 && 95 ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mediaType) !== -1 &&
84 validator.isLength(url.href, { min: 5 }) && 96 validator.isLength(url.href, { min: 5 }) &&
85 validator.isInt(url.height + '', { min: 0 }) 97 validator.isInt(url.height + '', { min: 0 })
86 ) || 98 ) ||