diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-11 16:27:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-13 14:05:49 +0200 |
commit | c48e82b5e0478434de30626d14594a97f2402e7c (patch) | |
tree | a78e5272bd0fe4f5b41831e571e02d05f1515b82 /server/helpers/custom-validators/activitypub/videos.ts | |
parent | a651038487faa838bda3ce04695b08bc65baff70 (diff) | |
download | PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.gz PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.zst PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.zip |
Basic video redundancy implementation
Diffstat (limited to 'server/helpers/custom-validators/activitypub/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 0362f43ab..f76eba474 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -75,6 +75,30 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { | |||
75 | video.attributedTo.length !== 0 | 75 | video.attributedTo.length !== 0 |
76 | } | 76 | } |
77 | 77 | ||
78 | function isRemoteVideoUrlValid (url: any) { | ||
79 | // FIXME: Old bug, we used the width to represent the resolution. Remove it in a few release (currently beta.11) | ||
80 | if (url.width && !url.height) url.height = url.width | ||
81 | |||
82 | return url.type === 'Link' && | ||
83 | ( | ||
84 | ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && | ||
85 | isActivityPubUrlValid(url.href) && | ||
86 | validator.isInt(url.height + '', { min: 0 }) && | ||
87 | validator.isInt(url.size + '', { min: 0 }) && | ||
88 | (!url.fps || validator.isInt(url.fps + '', { min: 0 })) | ||
89 | ) || | ||
90 | ( | ||
91 | ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && | ||
92 | isActivityPubUrlValid(url.href) && | ||
93 | validator.isInt(url.height + '', { min: 0 }) | ||
94 | ) || | ||
95 | ( | ||
96 | ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 && | ||
97 | validator.isLength(url.href, { min: 5 }) && | ||
98 | validator.isInt(url.height + '', { min: 0 }) | ||
99 | ) | ||
100 | } | ||
101 | |||
78 | // --------------------------------------------------------------------------- | 102 | // --------------------------------------------------------------------------- |
79 | 103 | ||
80 | export { | 104 | export { |
@@ -83,7 +107,8 @@ export { | |||
83 | isVideoTorrentDeleteActivityValid, | 107 | isVideoTorrentDeleteActivityValid, |
84 | isRemoteStringIdentifierValid, | 108 | isRemoteStringIdentifierValid, |
85 | isVideoFlagValid, | 109 | isVideoFlagValid, |
86 | sanitizeAndCheckVideoTorrentObject | 110 | sanitizeAndCheckVideoTorrentObject, |
111 | isRemoteVideoUrlValid | ||
87 | } | 112 | } |
88 | 113 | ||
89 | // --------------------------------------------------------------------------- | 114 | // --------------------------------------------------------------------------- |
@@ -147,26 +172,4 @@ function setRemoteVideoTruncatedContent (video: any) { | |||
147 | return true | 172 | return true |
148 | } | 173 | } |
149 | 174 | ||
150 | function isRemoteVideoUrlValid (url: any) { | ||
151 | // FIXME: Old bug, we used the width to represent the resolution. Remove it in a few realease (currently beta.11) | ||
152 | if (url.width && !url.height) url.height = url.width | ||
153 | 175 | ||
154 | return url.type === 'Link' && | ||
155 | ( | ||
156 | ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && | ||
157 | isActivityPubUrlValid(url.href) && | ||
158 | validator.isInt(url.height + '', { min: 0 }) && | ||
159 | validator.isInt(url.size + '', { min: 0 }) && | ||
160 | (!url.fps || validator.isInt(url.fps + '', { min: 0 })) | ||
161 | ) || | ||
162 | ( | ||
163 | ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && | ||
164 | isActivityPubUrlValid(url.href) && | ||
165 | validator.isInt(url.height + '', { min: 0 }) | ||
166 | ) || | ||
167 | ( | ||
168 | ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 && | ||
169 | validator.isLength(url.href, { min: 5 }) && | ||
170 | validator.isInt(url.height + '', { min: 0 }) | ||
171 | ) | ||
172 | } | ||