X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-format-utils.ts;h=551cb2842aa6883ae69f02506c802c843b63e9ec;hb=1c5e49e75284100b7b1fc8b4e73c8ba53fe22e89;hp=9dc3e772273916d38686f5644dcd35871a61e06b;hpb=d9a2a03196275065c28f4a0b7d4d7bc9992d77a1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 9dc3e7722..551cb2842 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -14,11 +14,11 @@ import { } from '../../lib/activitypub/url' import { MStreamingPlaylistRedundanciesOpt, + MVideo, MVideoAP, MVideoFile, MVideoFormattable, - MVideoFormattableDetails, - MVideoWithHost + MVideoFormattableDetails } from '../../types/models' import { MVideoFileRedundanciesOpt } from '../../types/models/video/video-file' import { VideoModel } from './video' @@ -188,9 +188,12 @@ function sortByResolutionDesc (fileA: MVideoFile, fileB: MVideoFile) { function videoFilesModelToFormattedJSON ( video: MVideoFormattableDetails, - videoFiles: MVideoFileRedundanciesOpt[] + videoFiles: MVideoFileRedundanciesOpt[], + includeMagnet = true ): VideoFile[] { - const trackerUrls = video.getTrackerUrls() + const trackerUrls = includeMagnet + ? video.getTrackerUrls() + : [] return [ ...videoFiles ] .filter(f => !f.isLive()) @@ -202,8 +205,9 @@ function videoFilesModelToFormattedJSON ( label: videoFile.resolution + 'p' }, - // FIXME: deprecated in 3.2 - magnetUri: generateMagnetUri(video, videoFile, trackerUrls), + magnetUri: includeMagnet && videoFile.hasTorrent() + ? generateMagnetUri(video, videoFile, trackerUrls) + : undefined, size: videoFile.size, fps: videoFile.fps, @@ -221,7 +225,7 @@ function videoFilesModelToFormattedJSON ( function addVideoFilesInAPAcc ( acc: ActivityUrlObject[] | ActivityTagObject[], - video: MVideoWithHost, + video: MVideo, files: MVideoFile[] ) { const trackerUrls = video.getTrackerUrls() @@ -249,19 +253,21 @@ function addVideoFilesInAPAcc ( fps: file.fps }) - acc.push({ - type: 'Link', - mediaType: 'application/x-bittorrent' as 'application/x-bittorrent', - href: file.getTorrentUrl(), - height: file.resolution - }) - - acc.push({ - type: 'Link', - mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet', - href: generateMagnetUri(video, file, trackerUrls), - height: file.resolution - }) + if (file.hasTorrent()) { + acc.push({ + type: 'Link', + mediaType: 'application/x-bittorrent' as 'application/x-bittorrent', + href: file.getTorrentUrl(), + height: file.resolution + }) + + acc.push({ + type: 'Link', + mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet', + href: generateMagnetUri(video, file, trackerUrls), + height: file.resolution + }) + } } }