diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-07-25 22:01:25 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2018-07-25 22:01:25 +0200 |
commit | c1e791bad0b079af67398f6407221e6dcbb573dd (patch) | |
tree | 82e5944b4458dd35aa482a38f6b650eb93bb89ad /server/lib/activitypub/videos.ts | |
parent | 5f7021c33d31c5255b995ae0ff86b5bbea4ea4b9 (diff) | |
download | PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.gz PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.zst PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.zip |
expliciting type checks and predicates (server only)
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index fdc082b61..2944cb729 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -88,17 +88,17 @@ async function videoActivityObjectToDBAttributes ( | |||
88 | const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED | 88 | const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED |
89 | const duration = videoObject.duration.replace(/[^\d]+/, '') | 89 | const duration = videoObject.duration.replace(/[^\d]+/, '') |
90 | 90 | ||
91 | let language: string = null | 91 | let language: string | undefined |
92 | if (videoObject.language) { | 92 | if (videoObject.language) { |
93 | language = videoObject.language.identifier | 93 | language = videoObject.language.identifier |
94 | } | 94 | } |
95 | 95 | ||
96 | let category: number = null | 96 | let category: number | undefined |
97 | if (videoObject.category) { | 97 | if (videoObject.category) { |
98 | category = parseInt(videoObject.category.identifier, 10) | 98 | category = parseInt(videoObject.category.identifier, 10) |
99 | } | 99 | } |
100 | 100 | ||
101 | let licence: number = null | 101 | let licence: number | undefined |
102 | if (videoObject.licence) { | 102 | if (videoObject.licence) { |
103 | licence = parseInt(videoObject.licence.identifier, 10) | 103 | licence = parseInt(videoObject.licence.identifier, 10) |
104 | } | 104 | } |
@@ -143,7 +143,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje | |||
143 | throw new Error('Cannot find video files for ' + videoCreated.url) | 143 | throw new Error('Cannot find video files for ' + videoCreated.url) |
144 | } | 144 | } |
145 | 145 | ||
146 | const attributes = [] | 146 | const attributes: VideoFileModel[] = [] |
147 | for (const fileUrl of fileUrls) { | 147 | for (const fileUrl of fileUrls) { |
148 | // Fetch associated magnet uri | 148 | // Fetch associated magnet uri |
149 | const magnet = videoObject.url.find(u => { | 149 | const magnet = videoObject.url.find(u => { |
@@ -153,7 +153,11 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje | |||
153 | if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href) | 153 | if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href) |
154 | 154 | ||
155 | const parsed = magnetUtil.decode(magnet.href) | 155 | const parsed = magnetUtil.decode(magnet.href) |
156 | if (!parsed || isVideoFileInfoHashValid(parsed.infoHash) === false) throw new Error('Cannot parse magnet URI ' + magnet.href) | 156 | if (!parsed || |
157 | (parsed.infoHash && | ||
158 | (isVideoFileInfoHashValid(parsed.infoHash) === false))) { | ||
159 | throw new Error('Cannot parse magnet URI ' + magnet.href) | ||
160 | } | ||
157 | 161 | ||
158 | const attribute = { | 162 | const attribute = { |
159 | extname: VIDEO_MIMETYPE_EXT[ fileUrl.mimeType ], | 163 | extname: VIDEO_MIMETYPE_EXT[ fileUrl.mimeType ], |
@@ -161,7 +165,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje | |||
161 | resolution: fileUrl.width, | 165 | resolution: fileUrl.width, |
162 | size: fileUrl.size, | 166 | size: fileUrl.size, |
163 | videoId: videoCreated.id | 167 | videoId: videoCreated.id |
164 | } | 168 | } as VideoFileModel |
165 | attributes.push(attribute) | 169 | attributes.push(attribute) |
166 | } | 170 | } |
167 | 171 | ||