aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-07-25 22:01:25 +0200
committerRigel Kent <sendmemail@rigelk.eu>2018-07-25 22:01:25 +0200
commitc1e791bad0b079af67398f6407221e6dcbb573dd (patch)
tree82e5944b4458dd35aa482a38f6b650eb93bb89ad /server/lib/activitypub
parent5f7021c33d31c5255b995ae0ff86b5bbea4ea4b9 (diff)
downloadPeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.gz
PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.zst
PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.zip
expliciting type checks and predicates (server only)
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/audience.ts6
-rw-r--r--server/lib/activitypub/videos.ts16
2 files changed, 13 insertions, 9 deletions
diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts
index 7164135b6..7b4067c11 100644
--- a/server/lib/activitypub/audience.ts
+++ b/server/lib/activitypub/audience.ts
@@ -20,7 +20,7 @@ function getVideoCommentAudience (
20 isOrigin = false 20 isOrigin = false
21) { 21) {
22 const to = [ ACTIVITY_PUB.PUBLIC ] 22 const to = [ ACTIVITY_PUB.PUBLIC ]
23 const cc = [] 23 const cc: string[] = []
24 24
25 // Owner of the video we comment 25 // Owner of the video we comment
26 if (isOrigin === false) { 26 if (isOrigin === false) {
@@ -60,8 +60,8 @@ function getAudience (actorSender: ActorModel, isPublic = true) {
60} 60}
61 61
62function buildAudience (followerUrls: string[], isPublic = true) { 62function buildAudience (followerUrls: string[], isPublic = true) {
63 let to = [] 63 let to: string[] = []
64 let cc = [] 64 let cc: string[] = []
65 65
66 if (isPublic) { 66 if (isPublic) {
67 to = [ ACTIVITY_PUB.PUBLIC ] 67 to = [ ACTIVITY_PUB.PUBLIC ]
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