diff options
author | Chocobozzz <me@florianbigard.com> | 2020-09-17 13:59:02 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | de6310b2fcbb8a6b79c546b23dfa1920724faaa7 (patch) | |
tree | 57e73811ef2cf0c903782704284c9cbfc1598adb /server/lib/activitypub | |
parent | 1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb (diff) | |
download | PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.tar.gz PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.tar.zst PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.zip |
Handle live federation
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 22 |
3 files changed, 15 insertions, 15 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 74f1032e2..f84992489 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { isRedundancyAccepted } from '@server/lib/redundancy' | 1 | import { isRedundancyAccepted } from '@server/lib/redundancy' |
2 | import { ActivityCreate, CacheFileObject, VideoTorrentObject } from '../../../../shared' | 2 | import { ActivityCreate, CacheFileObject, VideoObject } from '../../../../shared' |
3 | import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' | 3 | import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' |
4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | 4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' |
5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
@@ -52,7 +52,7 @@ export { | |||
52 | // --------------------------------------------------------------------------- | 52 | // --------------------------------------------------------------------------- |
53 | 53 | ||
54 | async function processCreateVideo (activity: ActivityCreate, notify: boolean) { | 54 | async function processCreateVideo (activity: ActivityCreate, notify: boolean) { |
55 | const videoToCreateData = activity.object as VideoTorrentObject | 55 | const videoToCreateData = activity.object as VideoObject |
56 | 56 | ||
57 | const syncParam = { likes: false, dislikes: false, shares: false, comments: false, thumbnail: true, refreshVideo: false } | 57 | const syncParam = { likes: false, dislikes: false, shares: false, comments: false, thumbnail: true, refreshVideo: false } |
58 | const { video, created } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData, syncParam }) | 58 | const { video, created } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData, syncParam }) |
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 1bdf23d6f..6d2fff3fe 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { ActivityUpdate, CacheFileObject, VideoTorrentObject } from '../../../../shared/models/activitypub' | 1 | import { ActivityUpdate, CacheFileObject, VideoObject } from '../../../../shared/models/activitypub' |
2 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' | 2 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' |
3 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
@@ -55,7 +55,7 @@ export { | |||
55 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
56 | 56 | ||
57 | async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpdate) { | 57 | async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpdate) { |
58 | const videoObject = activity.object as VideoTorrentObject | 58 | const videoObject = activity.object as VideoObject |
59 | 59 | ||
60 | if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { | 60 | if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { |
61 | logger.debug('Video sent by update is not valid.', { videoObject }) | 61 | logger.debug('Video sent by update is not valid.', { videoObject }) |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 096884776..049e06cff 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -15,7 +15,7 @@ import { | |||
15 | ActivityVideoUrlObject, | 15 | ActivityVideoUrlObject, |
16 | VideoState | 16 | VideoState |
17 | } from '../../../shared/index' | 17 | } from '../../../shared/index' |
18 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 18 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
19 | import { VideoPrivacy } from '../../../shared/models/videos' | 19 | import { VideoPrivacy } from '../../../shared/models/videos' |
20 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 20 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
21 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 21 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' |
@@ -38,7 +38,6 @@ import { | |||
38 | } from '../../initializers/constants' | 38 | } from '../../initializers/constants' |
39 | import { sequelizeTypescript } from '../../initializers/database' | 39 | import { sequelizeTypescript } from '../../initializers/database' |
40 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | 40 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
41 | import { TagModel } from '../../models/video/tag' | ||
42 | import { VideoModel } from '../../models/video/video' | 41 | import { VideoModel } from '../../models/video/video' |
43 | import { VideoCaptionModel } from '../../models/video/video-caption' | 42 | import { VideoCaptionModel } from '../../models/video/video-caption' |
44 | import { VideoCommentModel } from '../../models/video/video-comment' | 43 | import { VideoCommentModel } from '../../models/video/video-comment' |
@@ -104,7 +103,7 @@ async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVid | |||
104 | } | 103 | } |
105 | } | 104 | } |
106 | 105 | ||
107 | async function fetchRemoteVideo (videoUrl: string): Promise<{ response: request.RequestResponse, videoObject: VideoTorrentObject }> { | 106 | async function fetchRemoteVideo (videoUrl: string): Promise<{ response: request.RequestResponse, videoObject: VideoObject }> { |
108 | const options = { | 107 | const options = { |
109 | uri: videoUrl, | 108 | uri: videoUrl, |
110 | method: 'GET', | 109 | method: 'GET', |
@@ -136,7 +135,7 @@ async function fetchRemoteVideoDescription (video: MVideoAccountLight) { | |||
136 | return body.description ? body.description : '' | 135 | return body.description ? body.description : '' |
137 | } | 136 | } |
138 | 137 | ||
139 | function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) { | 138 | function getOrCreateVideoChannelFromVideoObject (videoObject: VideoObject) { |
140 | const channel = videoObject.attributedTo.find(a => a.type === 'Group') | 139 | const channel = videoObject.attributedTo.find(a => a.type === 'Group') |
141 | if (!channel) throw new Error('Cannot find associated video channel to video ' + videoObject.url) | 140 | if (!channel) throw new Error('Cannot find associated video channel to video ' + videoObject.url) |
142 | 141 | ||
@@ -155,7 +154,7 @@ type SyncParam = { | |||
155 | thumbnail: boolean | 154 | thumbnail: boolean |
156 | refreshVideo?: boolean | 155 | refreshVideo?: boolean |
157 | } | 156 | } |
158 | async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoTorrentObject, syncParam: SyncParam) { | 157 | async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoObject, syncParam: SyncParam) { |
159 | logger.info('Adding likes/dislikes/shares/comments of video %s.', video.uuid) | 158 | logger.info('Adding likes/dislikes/shares/comments of video %s.', video.uuid) |
160 | 159 | ||
161 | const jobPayloads: ActivitypubHttpFetcherPayload[] = [] | 160 | const jobPayloads: ActivitypubHttpFetcherPayload[] = [] |
@@ -294,7 +293,7 @@ async function getOrCreateVideoAndAccountAndChannel ( | |||
294 | 293 | ||
295 | async function updateVideoFromAP (options: { | 294 | async function updateVideoFromAP (options: { |
296 | video: MVideoAccountLightBlacklistAllFiles | 295 | video: MVideoAccountLightBlacklistAllFiles |
297 | videoObject: VideoTorrentObject | 296 | videoObject: VideoObject |
298 | account: MAccountIdActor | 297 | account: MAccountIdActor |
299 | channel: MChannelDefault | 298 | channel: MChannelDefault |
300 | overrideTo?: string[] | 299 | overrideTo?: string[] |
@@ -538,7 +537,7 @@ function isAPHashTagObject (url: any): url is ActivityHashTagObject { | |||
538 | return url && url.type === 'Hashtag' | 537 | return url && url.type === 'Hashtag' |
539 | } | 538 | } |
540 | 539 | ||
541 | async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAccountLight, waitThumbnail = false) { | 540 | async function createVideo (videoObject: VideoObject, channel: MChannelAccountLight, waitThumbnail = false) { |
542 | logger.debug('Adding remote video %s.', videoObject.id) | 541 | logger.debug('Adding remote video %s.', videoObject.id) |
543 | 542 | ||
544 | const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, videoObject.to) | 543 | const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, videoObject.to) |
@@ -632,7 +631,7 @@ async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAc | |||
632 | return { autoBlacklisted, videoCreated } | 631 | return { autoBlacklisted, videoCreated } |
633 | } | 632 | } |
634 | 633 | ||
635 | function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoTorrentObject, to: string[] = []) { | 634 | function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoObject, to: string[] = []) { |
636 | const privacy = to.includes(ACTIVITY_PUB.PUBLIC) | 635 | const privacy = to.includes(ACTIVITY_PUB.PUBLIC) |
637 | ? VideoPrivacy.PUBLIC | 636 | ? VideoPrivacy.PUBLIC |
638 | : VideoPrivacy.UNLISTED | 637 | : VideoPrivacy.UNLISTED |
@@ -664,6 +663,7 @@ function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObjec | |||
664 | commentsEnabled: videoObject.commentsEnabled, | 663 | commentsEnabled: videoObject.commentsEnabled, |
665 | downloadEnabled: videoObject.downloadEnabled, | 664 | downloadEnabled: videoObject.downloadEnabled, |
666 | waitTranscoding: videoObject.waitTranscoding, | 665 | waitTranscoding: videoObject.waitTranscoding, |
666 | isLive: videoObject.isLiveBroadcast, | ||
667 | state: videoObject.state, | 667 | state: videoObject.state, |
668 | channelId: videoChannel.id, | 668 | channelId: videoChannel.id, |
669 | duration: parseInt(duration, 10), | 669 | duration: parseInt(duration, 10), |
@@ -732,7 +732,7 @@ function videoFileActivityUrlToDBAttributes ( | |||
732 | return attributes | 732 | return attributes |
733 | } | 733 | } |
734 | 734 | ||
735 | function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObject: VideoTorrentObject, videoFiles: MVideoFile[]) { | 735 | function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObject: VideoObject, videoFiles: MVideoFile[]) { |
736 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] | 736 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] |
737 | if (playlistUrls.length === 0) return [] | 737 | if (playlistUrls.length === 0) return [] |
738 | 738 | ||
@@ -766,7 +766,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObjec | |||
766 | return attributes | 766 | return attributes |
767 | } | 767 | } |
768 | 768 | ||
769 | function getThumbnailFromIcons (videoObject: VideoTorrentObject) { | 769 | function getThumbnailFromIcons (videoObject: VideoObject) { |
770 | let validIcons = videoObject.icon.filter(i => i.width > THUMBNAILS_SIZE.minWidth) | 770 | let validIcons = videoObject.icon.filter(i => i.width > THUMBNAILS_SIZE.minWidth) |
771 | // Fallback if there are not valid icons | 771 | // Fallback if there are not valid icons |
772 | if (validIcons.length === 0) validIcons = videoObject.icon | 772 | if (validIcons.length === 0) validIcons = videoObject.icon |
@@ -774,7 +774,7 @@ function getThumbnailFromIcons (videoObject: VideoTorrentObject) { | |||
774 | return minBy(validIcons, 'width') | 774 | return minBy(validIcons, 'width') |
775 | } | 775 | } |
776 | 776 | ||
777 | function getPreviewFromIcons (videoObject: VideoTorrentObject) { | 777 | function getPreviewFromIcons (videoObject: VideoObject) { |
778 | const validIcons = videoObject.icon.filter(i => i.width > PREVIEWS_SIZE.minWidth) | 778 | const validIcons = videoObject.icon.filter(i => i.width > PREVIEWS_SIZE.minWidth) |
779 | 779 | ||
780 | // FIXME: don't put a fallback here for compatibility with PeerTube <2.2 | 780 | // FIXME: don't put a fallback here for compatibility with PeerTube <2.2 |