]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-format-utils.ts
Change models
[github/Chocobozzz/PeerTube.git] / server / models / video / video-format-utils.ts
index fae38507bdfef924979c68aaebb4a58eca2c787b..7a9513cbe5d776c21f2b49983d3854832888cfbb 100644 (file)
@@ -2,7 +2,7 @@ import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
 import { VideoModel } from './video'
 import { VideoFileModel } from './video-file'
 import { ActivityUrlObject, VideoTorrentObject } from '../../../shared/models/activitypub/objects'
-import { CONFIG, THUMBNAILS_SIZE, VIDEO_EXT_MIMETYPE } from '../../initializers'
+import { CONFIG, MIMETYPES, THUMBNAILS_SIZE } from '../../initializers'
 import { VideoCaptionModel } from './video-caption'
 import {
   getVideoCommentsActivityPubUrl,
@@ -10,8 +10,10 @@ import {
   getVideoLikesActivityPubUrl,
   getVideoSharesActivityPubUrl
 } from '../../lib/activitypub'
+import { isArray } from '../../helpers/custom-validators/misc'
 
 export type VideoFormattingJSONOptions = {
+  completeDescription?: boolean
   additionalAttributes: {
     state?: boolean,
     waitTranscoding?: boolean,
@@ -23,6 +25,8 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
   const formattedAccount = video.VideoChannel.Account.toFormattedJSON()
   const formattedVideoChannel = video.VideoChannel.toFormattedJSON()
 
+  const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined
+
   const videoObject: Video = {
     id: video.id,
     uuid: video.uuid,
@@ -44,7 +48,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
       label: VideoModel.getPrivacyLabel(video.privacy)
     },
     nsfw: video.nsfw,
-    description: video.getTruncatedDescription(),
+    description: options && options.completeDescription === true ? video.description : video.getTruncatedDescription(),
     isLocal: video.isOwned(),
     duration: video.duration,
     views: video.views,
@@ -56,6 +60,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
     createdAt: video.createdAt,
     updatedAt: video.updatedAt,
     publishedAt: video.publishedAt,
+    originallyPublishedAt: video.originallyPublishedAt,
     account: {
       id: formattedAccount.id,
       uuid: formattedAccount.uuid,
@@ -73,7 +78,11 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
       url: formattedVideoChannel.url,
       host: formattedVideoChannel.host,
       avatar: formattedVideoChannel.avatar
-    }
+    },
+
+    userHistory: userHistory ? {
+      currentTime: userHistory.currentTime
+    } : undefined
   }
 
   if (options) {
@@ -112,12 +121,13 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails {
     }
   })
 
+  const tags = video.Tags ? video.Tags.map(t => t.name) : []
   const detailsJson = {
     support: video.support,
-    descriptionPath: video.getDescriptionPath(),
+    descriptionPath: video.getDescriptionAPIPath(),
     channel: video.VideoChannel.toFormattedJSON(),
     account: video.VideoChannel.Account.toFormattedJSON(),
-    tags: video.Tags.map(t => t.name),
+    tags,
     commentsEnabled: video.commentsEnabled,
     waitTranscoding: video.waitTranscoding,
     state: {
@@ -198,7 +208,8 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
   for (const file of video.VideoFiles) {
     url.push({
       type: 'Link',
-      mimeType: VIDEO_EXT_MIMETYPE[ file.extname ] as any,
+      mimeType: MIMETYPES.VIDEO.EXT_MIMETYPE[ file.extname ] as any,
+      mediaType: MIMETYPES.VIDEO.EXT_MIMETYPE[ file.extname ] as any,
       href: video.getVideoFileUrl(file, baseUrlHttp),
       height: file.resolution,
       size: file.size,
@@ -208,6 +219,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
     url.push({
       type: 'Link',
       mimeType: 'application/x-bittorrent' as 'application/x-bittorrent',
+      mediaType: 'application/x-bittorrent' as 'application/x-bittorrent',
       href: video.getTorrentUrl(file, baseUrlHttp),
       height: file.resolution
     })
@@ -215,6 +227,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
     url.push({
       type: 'Link',
       mimeType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet',
+      mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet',
       href: video.generateMagnetUri(file, baseUrlHttp, baseUrlWs),
       height: file.resolution
     })
@@ -224,6 +237,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
   url.push({
     type: 'Link',
     mimeType: 'text/html',
+    mediaType: 'text/html',
     href: CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
   })
 
@@ -251,6 +265,9 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
     state: video.state,
     commentsEnabled: video.commentsEnabled,
     published: video.publishedAt.toISOString(),
+    originallyPublishedAt: video.originallyPublishedAt ?
+      video.originallyPublishedAt.toISOString() :
+      null,
     updated: video.updatedAt.toISOString(),
     mediaType: 'text/markdown',
     content: video.getTruncatedDescription(),