]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-format-utils.ts
Begin auth plugin support
[github/Chocobozzz/PeerTube.git] / server / models / video / video-format-utils.ts
index 55b0ed062576450de0cd08c4c44a767622607fed..365c9581e60ff25aa687a7d11d97e1d92db3cd1f 100644 (file)
@@ -23,6 +23,7 @@ import {
 import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
 import { VideoFile } from '@shared/models/videos/video-file.model'
 import { generateMagnetUri } from '@server/helpers/webtorrent'
+import { extractVideo } from '@server/lib/videos'
 
 export type VideoFormattingJSONOptions = {
   completeDescription?: boolean
@@ -180,6 +181,8 @@ function videoFilesModelToFormattedJSON (
   baseUrlWs: string,
   videoFiles: MVideoFileRedundanciesOpt[]
 ): VideoFile[] {
+  const video = extractVideo(model)
+
   return videoFiles
     .map(videoFile => {
       return {
@@ -193,7 +196,8 @@ function videoFilesModelToFormattedJSON (
         torrentUrl: model.getTorrentUrl(videoFile, baseUrlHttp),
         torrentDownloadUrl: model.getTorrentDownloadUrl(videoFile, baseUrlHttp),
         fileUrl: model.getVideoFileUrl(videoFile, baseUrlHttp),
-        fileDownloadUrl: model.getVideoFileDownloadUrl(videoFile, baseUrlHttp)
+        fileDownloadUrl: model.getVideoFileDownloadUrl(videoFile, baseUrlHttp),
+        metadataUrl: video.getVideoFileMetadataUrl(videoFile, baseUrlHttp)
       } as VideoFile
     })
     .sort((a, b) => {
@@ -220,6 +224,15 @@ function addVideoFilesInAPAcc (
       fps: file.fps
     })
 
+    acc.push({
+      type: 'Link',
+      rel: [ 'metadata', MIMETYPES.VIDEO.EXT_MIMETYPE[file.extname] ],
+      mediaType: 'application/json' as 'application/json',
+      href: extractVideo(model).getVideoFileMetadataUrl(file, baseUrlHttp),
+      height: file.resolution,
+      fps: file.fps
+    })
+
     acc.push({
       type: 'Link',
       mediaType: 'application/x-bittorrent' as 'application/x-bittorrent',
@@ -269,7 +282,15 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
     }
   }
 
-  const url: ActivityUrlObject[] = []
+  const url: ActivityUrlObject[] = [
+    // HTML url should be the first element in the array so Mastodon correctly displays the embed
+    {
+      type: 'Link',
+      mediaType: 'text/html',
+      href: WEBSERVER.URL + '/videos/watch/' + video.uuid
+    }
+  ]
+
   addVideoFilesInAPAcc(url, video, baseUrlHttp, baseUrlWs, video.VideoFiles || [])
 
   for (const playlist of (video.VideoStreamingPlaylists || [])) {
@@ -293,13 +314,6 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
     })
   }
 
-  // Add video url too
-  url.push({
-    type: 'Link',
-    mediaType: 'text/html',
-    href: WEBSERVER.URL + '/videos/watch/' + video.uuid
-  })
-
   const subtitleLanguage = []
   for (const caption of video.VideoCaptions) {
     subtitleLanguage.push({