diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-08 11:13:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-08 11:16:14 +0200 |
commit | ae9bbed46dbc8d9870c9feb66bbada484c1c7582 (patch) | |
tree | 69a04af65274f9f39cb439384ad58b1fc1058ba0 /server/lib/activitypub | |
parent | 14aed608f540b587b3ab2529d06690815214d232 (diff) | |
download | PeerTube-ae9bbed46dbc8d9870c9feb66bbada484c1c7582.tar.gz PeerTube-ae9bbed46dbc8d9870c9feb66bbada484c1c7582.tar.zst PeerTube-ae9bbed46dbc8d9870c9feb66bbada484c1c7582.zip |
Update P2P media loader peer version
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/videos.ts | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index d935e3f90..339f8e797 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -290,7 +290,11 @@ async function updateVideoFromAP (options: { | |||
290 | } | 290 | } |
291 | 291 | ||
292 | { | 292 | { |
293 | const streamingPlaylistAttributes = streamingPlaylistActivityUrlToDBAttributes(options.video, options.videoObject) | 293 | const streamingPlaylistAttributes = streamingPlaylistActivityUrlToDBAttributes( |
294 | options.video, | ||
295 | options.videoObject, | ||
296 | options.video.VideoFiles | ||
297 | ) | ||
294 | const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a)) | 298 | const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a)) |
295 | 299 | ||
296 | // Remove video files that do not exist anymore | 300 | // Remove video files that do not exist anymore |
@@ -449,9 +453,9 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor | |||
449 | } | 453 | } |
450 | 454 | ||
451 | const videoFilePromises = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t })) | 455 | const videoFilePromises = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t })) |
452 | await Promise.all(videoFilePromises) | 456 | const videoFiles = await Promise.all(videoFilePromises) |
453 | 457 | ||
454 | const videoStreamingPlaylists = streamingPlaylistActivityUrlToDBAttributes(videoCreated, videoObject) | 458 | const videoStreamingPlaylists = streamingPlaylistActivityUrlToDBAttributes(videoCreated, videoObject, videoFiles) |
455 | const playlistPromises = videoStreamingPlaylists.map(p => VideoStreamingPlaylistModel.create(p, { transaction: t })) | 459 | const playlistPromises = videoStreamingPlaylists.map(p => VideoStreamingPlaylistModel.create(p, { transaction: t })) |
456 | await Promise.all(playlistPromises) | 460 | await Promise.all(playlistPromises) |
457 | 461 | ||
@@ -575,20 +579,12 @@ function videoFileActivityUrlToDBAttributes (video: VideoModel, videoObject: Vid | |||
575 | return attributes | 579 | return attributes |
576 | } | 580 | } |
577 | 581 | ||
578 | function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObject: VideoTorrentObject) { | 582 | function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObject: VideoTorrentObject, videoFiles: VideoFileModel[]) { |
579 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] | 583 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] |
580 | if (playlistUrls.length === 0) return [] | 584 | if (playlistUrls.length === 0) return [] |
581 | 585 | ||
582 | const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = [] | 586 | const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = [] |
583 | for (const playlistUrlObject of playlistUrls) { | 587 | for (const playlistUrlObject of playlistUrls) { |
584 | const p2pMediaLoaderInfohashes = playlistUrlObject.tag | ||
585 | .filter(t => t.type === 'Infohash') | ||
586 | .map(t => t.name) | ||
587 | if (p2pMediaLoaderInfohashes.length === 0) { | ||
588 | logger.warn('No infohashes found in AP playlist object.', { playlistUrl: playlistUrlObject }) | ||
589 | continue | ||
590 | } | ||
591 | |||
592 | const segmentsSha256UrlObject = playlistUrlObject.tag | 588 | const segmentsSha256UrlObject = playlistUrlObject.tag |
593 | .find(t => { | 589 | .find(t => { |
594 | return isAPPlaylistSegmentHashesUrlObject(t) | 590 | return isAPPlaylistSegmentHashesUrlObject(t) |
@@ -602,7 +598,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObj | |||
602 | type: VideoStreamingPlaylistType.HLS, | 598 | type: VideoStreamingPlaylistType.HLS, |
603 | playlistUrl: playlistUrlObject.href, | 599 | playlistUrl: playlistUrlObject.href, |
604 | segmentsSha256Url: segmentsSha256UrlObject.href, | 600 | segmentsSha256Url: segmentsSha256UrlObject.href, |
605 | p2pMediaLoaderInfohashes, | 601 | p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrlObject.href, videoFiles), |
606 | videoId: video.id | 602 | videoId: video.id |
607 | } | 603 | } |
608 | 604 | ||