aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-05-31 15:14:40 +0200
committerChocobozzz <me@florianbigard.com>2019-05-31 15:17:04 +0200
commitee79b60e4e500a1dc7db8bcee560d9a4a1a5d17a (patch)
treed18b7f8667ee41923c89744586c1b71b8691f4a2
parent57cfff78858b2360d9e038e2a504b761cb51da47 (diff)
downloadPeerTube-ee79b60e4e500a1dc7db8bcee560d9a4a1a5d17a.tar.gz
PeerTube-ee79b60e4e500a1dc7db8bcee560d9a4a1a5d17a.tar.zst
PeerTube-ee79b60e4e500a1dc7db8bcee560d9a4a1a5d17a.zip
More robust federation
In particular when fetching pleroma outbox
-rw-r--r--client/src/app/+accounts/account-video-channels/account-video-channels.component.scss4
-rw-r--r--client/src/app/shared/video/video-details.model.ts3
-rw-r--r--client/src/app/shared/video/video.model.ts2
-rw-r--r--server/helpers/custom-validators/activitypub/video-comments.ts3
-rw-r--r--server/lib/activitypub/crawl.ts19
-rw-r--r--server/lib/activitypub/process/process-announce.ts15
-rw-r--r--server/lib/activitypub/process/process-create.ts13
-rw-r--r--server/lib/activitypub/video-comments.ts4
8 files changed, 48 insertions, 15 deletions
diff --git a/client/src/app/+accounts/account-video-channels/account-video-channels.component.scss b/client/src/app/+accounts/account-video-channels/account-video-channels.component.scss
index f2604684e..d9f78bdcd 100644
--- a/client/src/app/+accounts/account-video-channels/account-video-channels.component.scss
+++ b/client/src/app/+accounts/account-video-channels/account-video-channels.component.scss
@@ -10,4 +10,8 @@
10 @include miniature-rows; 10 @include miniature-rows;
11 11
12 padding-top: 0 !important; 12 padding-top: 0 !important;
13
14 .section-title {
15 align-items: center;
16 }
13} 17}
diff --git a/client/src/app/shared/video/video-details.model.ts b/client/src/app/shared/video/video-details.model.ts
index 22f024656..e4d443a06 100644
--- a/client/src/app/shared/video/video-details.model.ts
+++ b/client/src/app/shared/video/video-details.model.ts
@@ -1,5 +1,4 @@
1import { UserRight, VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared' 1import { VideoConstant, VideoDetails as VideoDetailsServerModel, VideoFile, VideoState } from '../../../../../shared'
2import { AuthUser } from '../../core'
3import { Video } from '../../shared/video/video.model' 2import { Video } from '../../shared/video/video.model'
4import { Account } from '@app/shared/account/account.model' 3import { Account } from '@app/shared/account/account.model'
5import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 4import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts
index 0cef3eb8f..6f9de9241 100644
--- a/client/src/app/shared/video/video.model.ts
+++ b/client/src/app/shared/video/video.model.ts
@@ -52,7 +52,6 @@ export class Video implements VideoServerModel {
52 52
53 account: { 53 account: {
54 id: number 54 id: number
55 uuid: string
56 name: string 55 name: string
57 displayName: string 56 displayName: string
58 url: string 57 url: string
@@ -62,7 +61,6 @@ export class Video implements VideoServerModel {
62 61
63 channel: { 62 channel: {
64 id: number 63 id: number
65 uuid: string
66 name: string 64 name: string
67 displayName: string 65 displayName: string
68 url: string 66 url: string
diff --git a/server/helpers/custom-validators/activitypub/video-comments.ts b/server/helpers/custom-validators/activitypub/video-comments.ts
index 26c8c4cc6..e04c5388f 100644
--- a/server/helpers/custom-validators/activitypub/video-comments.ts
+++ b/server/helpers/custom-validators/activitypub/video-comments.ts
@@ -36,7 +36,8 @@ function normalizeComment (comment: any) {
36 if (!comment) return 36 if (!comment) return
37 37
38 if (typeof comment.url !== 'string') { 38 if (typeof comment.url !== 'string') {
39 comment.url = comment.url.href || comment.url.url 39 if (typeof comment.url === 'object') comment.url = comment.url.href || comment.url.url
40 else comment.url = comment.id
40 } 41 }
41 42
42 return 43 return
diff --git a/server/lib/activitypub/crawl.ts b/server/lib/activitypub/crawl.ts
index 686eef04d..9e469e3e6 100644
--- a/server/lib/activitypub/crawl.ts
+++ b/server/lib/activitypub/crawl.ts
@@ -28,13 +28,22 @@ async function crawlCollectionPage <T> (uri: string, handler: HandlerFunction<T>
28 let i = 0 28 let i = 0
29 let nextLink = firstBody.first 29 let nextLink = firstBody.first
30 while (nextLink && i < limit) { 30 while (nextLink && i < limit) {
31 // Don't crawl ourselves 31 let body: any
32 const remoteHost = parse(nextLink).host
33 if (remoteHost === WEBSERVER.HOST) continue
34 32
35 options.uri = nextLink 33 if (typeof nextLink === 'string') {
34 // Don't crawl ourselves
35 const remoteHost = parse(nextLink).host
36 if (remoteHost === WEBSERVER.HOST) continue
37
38 options.uri = nextLink
39
40 const res = await doRequest<ActivityPubOrderedCollection<T>>(options)
41 body = res.body
42 } else {
43 // nextLink is already the object we want
44 body = nextLink
45 }
36 46
37 const { body } = await doRequest<ActivityPubOrderedCollection<T>>(options)
38 nextLink = body.next 47 nextLink = body.next
39 i++ 48 i++
40 49
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 23310b41e..bbf1bd3a8 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -5,8 +5,9 @@ import { ActorModel } from '../../../models/activitypub/actor'
5import { VideoShareModel } from '../../../models/video/video-share' 5import { VideoShareModel } from '../../../models/video/video-share'
6import { forwardVideoRelatedActivity } from '../send/utils' 6import { forwardVideoRelatedActivity } from '../send/utils'
7import { getOrCreateVideoAndAccountAndChannel } from '../videos' 7import { getOrCreateVideoAndAccountAndChannel } from '../videos'
8import { VideoPrivacy } from '../../../../shared/models/videos'
9import { Notifier } from '../../notifier' 8import { Notifier } from '../../notifier'
9import { VideoModel } from '../../../models/video/video'
10import { logger } from '../../../helpers/logger'
10 11
11async function processAnnounceActivity (activity: ActivityAnnounce, actorAnnouncer: ActorModel) { 12async function processAnnounceActivity (activity: ActivityAnnounce, actorAnnouncer: ActorModel) {
12 return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity) 13 return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity)
@@ -23,7 +24,17 @@ export {
23async function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { 24async function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
24 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id 25 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
25 26
26 const { video, created: videoCreated } = await getOrCreateVideoAndAccountAndChannel({ videoObject: objectUri }) 27 let video: VideoModel
28 let videoCreated: boolean
29
30 try {
31 const result = await getOrCreateVideoAndAccountAndChannel({ videoObject: objectUri })
32 video = result.video
33 videoCreated = result.created
34 } catch (err) {
35 logger.debug('Cannot process share of %s. Maybe this is not a video object, so just skipping.', objectUri, { err })
36 return
37 }
27 38
28 await sequelizeTypescript.transaction(async t => { 39 await sequelizeTypescript.transaction(async t => {
29 // Add share entry 40 // Add share entry
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index e882669ce..e4c173e99 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -14,6 +14,7 @@ import { processDislikeActivity } from './process-dislike'
14import { processFlagActivity } from './process-flag' 14import { processFlagActivity } from './process-flag'
15import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' 15import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
16import { createOrUpdateVideoPlaylist } from '../playlist' 16import { createOrUpdateVideoPlaylist } from '../playlist'
17import { VideoModel } from '../../../models/video/video'
17 18
18async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) { 19async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) {
19 const activityObject = activity.object 20 const activityObject = activity.object
@@ -91,7 +92,17 @@ async function processCreateVideoComment (activity: ActivityCreate, byActor: Act
91 92
92 if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) 93 if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url)
93 94
94 const { video } = await resolveThread(commentObject.inReplyTo) 95 let video: VideoModel
96 try {
97 const resolveThreadResult = await resolveThread(commentObject.inReplyTo)
98 video = resolveThreadResult.video
99 } catch (err) {
100 logger.debug(
101 'Cannot process video comment because we could not resolve thread %s. Maybe it was not a video thread, so skip it.',
102 commentObject.inReplyTo,
103 { err }
104 )
105 }
95 106
96 const { comment, created } = await addVideoComment(video, commentObject.id) 107 const { comment, created } = await addVideoComment(video, commentObject.id)
97 108
diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts
index 18f44d50e..c3fc6b462 100644
--- a/server/lib/activitypub/video-comments.ts
+++ b/server/lib/activitypub/video-comments.ts
@@ -80,7 +80,8 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) {
80 return { comment, created } 80 return { comment, created }
81} 81}
82 82
83async function resolveThread (url: string, comments: VideoCommentModel[] = []) { 83type ResolveThreadResult = Promise<{ video: VideoModel, parents: VideoCommentModel[] }>
84async function resolveThread (url: string, comments: VideoCommentModel[] = []): ResolveThreadResult {
84 // Already have this comment? 85 // Already have this comment?
85 const commentFromDatabase = await VideoCommentModel.loadByUrlAndPopulateReplyAndVideo(url) 86 const commentFromDatabase = await VideoCommentModel.loadByUrlAndPopulateReplyAndVideo(url)
86 if (commentFromDatabase) { 87 if (commentFromDatabase) {
@@ -161,7 +162,6 @@ async function resolveThread (url: string, comments: VideoCommentModel[] = []) {
161 162
162 return resolveThread(body.inReplyTo, comments.concat([ comment ])) 163 return resolveThread(body.inReplyTo, comments.concat([ comment ]))
163 } 164 }
164
165} 165}
166 166
167export { 167export {