X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-format-utils.ts;h=4e7eb5f0c7cbb8225ab0f92dd9ed9afcf029b5a2;hb=453e83ea5d81d203ba34bc43cd5c2c750ba40568;hp=89992a5a8a7465a78564e0dc9e26bc4537b8bfbf;hpb=e8bafea35bc930cb8ac5b2d521a188642a1adffe;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 89992a5a8..4e7eb5f0c 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -1,6 +1,5 @@ import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' import { VideoModel } from './video' -import { VideoFileModel } from './video-file' import { ActivityPlaylistInfohashesObject, ActivityPlaylistSegmentHashesObject, @@ -17,7 +16,9 @@ import { } from '../../lib/activitypub' import { isArray } from '../../helpers/custom-validators/misc' import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model' -import { VideoStreamingPlaylistModel } from './video-streaming-playlist' +import { MVideo, MVideoAP, MVideoDetails } from '../../typings/models' +import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist' +import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' export type VideoFormattingJSONOptions = { completeDescription?: boolean @@ -26,7 +27,6 @@ export type VideoFormattingJSONOptions = { waitTranscoding?: boolean, scheduledUpdate?: boolean, blacklistInfo?: boolean - playlistInfo?: boolean } } function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormattingJSONOptions): Video { @@ -59,7 +59,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting views: video.views, likes: video.likes, dislikes: video.dislikes, - thumbnailPath: video.getThumbnailStaticPath(), + thumbnailPath: video.getMiniatureStaticPath(), previewPath: video.getPreviewStaticPath(), embedPath: video.getEmbedStaticPath(), createdAt: video.createdAt, @@ -98,23 +98,12 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting videoObject.blacklisted = !!video.VideoBlacklist videoObject.blacklistedReason = video.VideoBlacklist ? video.VideoBlacklist.reason : null } - - if (options.additionalAttributes.playlistInfo === true) { - // We filtered on a specific videoId/videoPlaylistId, that is unique - const playlistElement = video.VideoPlaylistElements[0] - - videoObject.playlistElement = { - position: playlistElement.position, - startTimestamp: playlistElement.startTimestamp, - stopTimestamp: playlistElement.stopTimestamp - } - } } return videoObject } -function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails { +function videoModelToFormattedDetailsJSON (video: MVideoDetails): VideoDetails { const formattedJson = video.toFormattedJSON({ additionalAttributes: { scheduledUpdate: true, @@ -126,7 +115,7 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails { const tags = video.Tags ? video.Tags.map(t => t.name) : [] - const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video, video.VideoStreamingPlaylists) + const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video.VideoStreamingPlaylists) const detailsJson = { support: video.support, @@ -154,7 +143,7 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails { return Object.assign(formattedJson, detailsJson) } -function streamingPlaylistsModelToFormattedJSON (video: VideoModel, playlists: VideoStreamingPlaylistModel[]): VideoStreamingPlaylist[] { +function streamingPlaylistsModelToFormattedJSON (playlists: MStreamingPlaylistRedundancies[]): VideoStreamingPlaylist[] { if (isArray(playlists) === false) return [] return playlists @@ -173,7 +162,7 @@ function streamingPlaylistsModelToFormattedJSON (video: VideoModel, playlists: V }) } -function videoFilesModelToFormattedJSON (video: VideoModel, videoFiles: VideoFileModel[]): VideoFile[] { +function videoFilesModelToFormattedJSON (video: MVideo, videoFiles: MVideoFileRedundanciesOpt[]): VideoFile[] { const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() return videoFiles @@ -201,7 +190,7 @@ function videoFilesModelToFormattedJSON (video: VideoModel, videoFiles: VideoFil }) } -function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject { +function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject { const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() if (!video.Tags) video.Tags = [] @@ -301,6 +290,8 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject { }) } + const miniature = video.getMiniature() + return { type: 'Video' as 'Video', id: video.url, @@ -326,10 +317,10 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject { subtitleLanguage, icon: { type: 'Image', - url: video.getThumbnail().getUrl(), + url: miniature.getFileUrl(), mediaType: 'image/jpeg', - width: video.getThumbnail().width, - height: video.getThumbnail().height + width: miniature.width, + height: miniature.height }, url, likes: getVideoLikesActivityPubUrl(video),