X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-format-utils.ts;h=905e8444997e8306d07773213960491ad9b41261;hb=35d50b7dd26b3cf646b8845784927bb1ef18dfb3;hp=fae38507bdfef924979c68aaebb4a58eca2c787b;hpb=098eb37797fdadd4adf660b76867da68061fd588;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index fae38507b..905e84449 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -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, @@ -73,7 +77,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 +120,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: {