aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-09-17 13:59:02 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commitde6310b2fcbb8a6b79c546b23dfa1920724faaa7 (patch)
tree57e73811ef2cf0c903782704284c9cbfc1598adb /server/lib/activitypub/videos.ts
parent1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb (diff)
downloadPeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.tar.gz
PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.tar.zst
PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.zip
Handle live federation
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r--server/lib/activitypub/videos.ts22
1 files changed, 11 insertions, 11 deletions
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'
18import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 18import { VideoObject } from '../../../shared/models/activitypub/objects'
19import { VideoPrivacy } from '../../../shared/models/videos' 19import { VideoPrivacy } from '../../../shared/models/videos'
20import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 20import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
21import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 21import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
@@ -38,7 +38,6 @@ import {
38} from '../../initializers/constants' 38} from '../../initializers/constants'
39import { sequelizeTypescript } from '../../initializers/database' 39import { sequelizeTypescript } from '../../initializers/database'
40import { AccountVideoRateModel } from '../../models/account/account-video-rate' 40import { AccountVideoRateModel } from '../../models/account/account-video-rate'
41import { TagModel } from '../../models/video/tag'
42import { VideoModel } from '../../models/video/video' 41import { VideoModel } from '../../models/video/video'
43import { VideoCaptionModel } from '../../models/video/video-caption' 42import { VideoCaptionModel } from '../../models/video/video-caption'
44import { VideoCommentModel } from '../../models/video/video-comment' 43import { VideoCommentModel } from '../../models/video/video-comment'
@@ -104,7 +103,7 @@ async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVid
104 } 103 }
105} 104}
106 105
107async function fetchRemoteVideo (videoUrl: string): Promise<{ response: request.RequestResponse, videoObject: VideoTorrentObject }> { 106async 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
139function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) { 138function 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}
158async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoTorrentObject, syncParam: SyncParam) { 157async 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
295async function updateVideoFromAP (options: { 294async 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
541async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAccountLight, waitThumbnail = false) { 540async 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
635function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoTorrentObject, to: string[] = []) { 634function 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
735function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObject: VideoTorrentObject, videoFiles: MVideoFile[]) { 735function 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
769function getThumbnailFromIcons (videoObject: VideoTorrentObject) { 769function 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
777function getPreviewFromIcons (videoObject: VideoTorrentObject) { 777function 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