X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=ea6c9d44ba080ddadbe2012bacfaaeb3a6cbb1c6;hb=1896bca09e088b0da9d5e845407ecebae330618c;hp=343abde4429ae84ddd1575ea2d48175d24802346;hpb=6939cbac48e0a9823b34577836480ae3c28186be;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 343abde44..ea6c9d44b 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -96,10 +96,11 @@ import { MVideoWithRights } from '../../types/models' import { MThumbnail } from '../../types/models/video/thumbnail' -import { MVideoFile, MVideoFileRedundanciesOpt, MVideoFileStreamingPlaylistVideo } from '../../types/models/video/video-file' +import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../types/models/video/video-file' import { VideoAbuseModel } from '../abuse/video-abuse' import { AccountModel } from '../account/account' import { AccountVideoRateModel } from '../account/account-video-rate' +import { UserModel } from '../account/user' import { UserVideoHistoryModel } from '../account/user-video-history' import { ActorModel } from '../activitypub/actor' import { AvatarModel } from '../avatar/avatar' @@ -129,7 +130,6 @@ import { VideoShareModel } from './video-share' import { VideoStreamingPlaylistModel } from './video-streaming-playlist' import { VideoTagModel } from './video-tag' import { VideoViewModel } from './video-view' -import { UserModel } from '../account/user' export enum ScopeNames { AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', @@ -152,8 +152,6 @@ export type ForAPIOptions = { videoPlaylistId?: number - withFiles?: boolean - withAccountBlockerIds?: number[] } @@ -220,13 +218,6 @@ export type AvailableForListIDsOptions = { } } - if (options.withFiles === true) { - include.push({ - model: VideoFileModel, - required: true - }) - } - if (options.videoPlaylistId) { include.push({ model: VideoPlaylistElementModel.unscoped(), @@ -1099,6 +1090,7 @@ export class VideoModel extends Model { const trendingDays = options.sort.endsWith('trending') ? CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS : undefined + const hot = options.sort.endsWith('hot') const serverActor = await getServerActor() @@ -1128,6 +1120,7 @@ export class VideoModel extends Model { user: options.user, historyOfUser: options.historyOfUser, trendingDays, + hot, search: options.search } @@ -1622,8 +1615,19 @@ export class VideoModel extends Model { const avatarKeys = [ 'id', 'filename', 'fileUrl', 'onDisk', 'createdAt', 'updatedAt' ] const actorKeys = [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ] const serverKeys = [ 'id', 'host' ] - const videoFileKeys = [ 'id', 'createdAt', 'updatedAt', 'resolution', 'size', 'extname', 'infoHash', 'fps', 'videoId' ] - const videoStreamingPlaylistKeys = [ 'id' ] + const videoFileKeys = [ + 'id', + 'createdAt', + 'updatedAt', + 'resolution', + 'size', + 'extname', + 'infoHash', + 'fps', + 'videoId', + 'videoStreamingPlaylistId' + ] + const videoStreamingPlaylistKeys = [ 'id', 'type', 'playlistUrl' ] const videoKeys = [ 'id', 'uuid', @@ -1882,17 +1886,21 @@ export class VideoModel extends Model { getFormattedVideoFilesJSON (): VideoFile[] { const { baseUrlHttp, baseUrlWs } = this.getBaseUrls() - let files: MVideoFileRedundanciesOpt[] = [] + let files: VideoFile[] = [] if (Array.isArray(this.VideoFiles)) { - files = files.concat(this.VideoFiles) + const result = videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, this.VideoFiles) + files = files.concat(result) } for (const p of (this.VideoStreamingPlaylists || [])) { - files = files.concat(p.VideoFiles || []) + p.Video = this + + const result = videoFilesModelToFormattedJSON(p, baseUrlHttp, baseUrlWs, p.VideoFiles) + files = files.concat(result) } - return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, files) + return files } toActivityPubObject (this: MVideoAP): VideoObject {