X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=ea6c9d44ba080ddadbe2012bacfaaeb3a6cbb1c6;hb=1896bca09e088b0da9d5e845407ecebae330618c;hp=d3fed338a725bf3189df25abe30bc3d818bdfc45;hpb=b49f22d8f9a52ab75fd38db2d377249eb58fa678;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index d3fed338a..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' @@ -151,8 +152,6 @@ export type ForAPIOptions = { videoPlaylistId?: number - withFiles?: boolean - withAccountBlockerIds?: number[] } @@ -219,13 +218,6 @@ export type AvailableForListIDsOptions = { } } - if (options.withFiles === true) { - include.push({ - model: VideoFileModel, - required: true - }) - } - if (options.videoPlaylistId) { include.push({ model: VideoPlaylistElementModel.unscoped(), @@ -1004,13 +996,15 @@ export class VideoModel extends Model { return result.map(v => v.id) } - static listUserVideosForApi ( - accountId: number, - start: number, - count: number, - sort: string, + static listUserVideosForApi (options: { + accountId: number + start: number + count: number + sort: string search?: string - ) { + }) { + const { accountId, start, count, sort, search } = options + function buildBaseQuery (): FindOptions { let baseQuery = { offset: start, @@ -1087,6 +1081,7 @@ export class VideoModel extends Model { user?: MUserAccountId historyOfUser?: MUserId countVideos?: boolean + search?: string }) { if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { throw new Error('Try to filter all-local but no user has not the see all videos right') @@ -1095,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() @@ -1123,7 +1119,9 @@ export class VideoModel extends Model { includeLocalVideos: options.includeLocalVideos, user: options.user, historyOfUser: options.historyOfUser, - trendingDays + trendingDays, + hot, + search: options.search } return VideoModel.getAvailableForApi(queryOptions, options.countVideos) @@ -1194,6 +1192,39 @@ export class VideoModel extends Model { return VideoModel.count(options) } + static countVideosUploadedByUserSince (userId: number, since: Date) { + const options = { + include: [ + { + model: VideoChannelModel.unscoped(), + required: true, + include: [ + { + model: AccountModel.unscoped(), + required: true, + include: [ + { + model: UserModel.unscoped(), + required: true, + where: { + id: userId + } + } + ] + } + ] + } + ], + where: { + createdAt: { + [Op.gte]: since + } + } + } + + return VideoModel.unscoped().count(options) + } + static countLivesOfAccount (accountId: number) { const options = { where: { @@ -1584,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', @@ -1602,6 +1644,7 @@ export class VideoModel extends Model { 'likes', 'dislikes', 'remote', + 'isLive', 'url', 'commentsEnabled', 'downloadEnabled', @@ -1730,6 +1773,7 @@ export class VideoModel extends Model { } getQualityFileBy (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { + // We first transcode to WebTorrent format, so try this array first if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) { const file = fun(this.VideoFiles, file => file.resolution) @@ -1764,6 +1808,10 @@ export class VideoModel extends Model { return Object.assign(file, { Video: this }) } + hasWebTorrentFiles () { + return Array.isArray(this.VideoFiles) === true && this.VideoFiles.length !== 0 + } + async addAndSaveThumbnail (thumbnail: MThumbnail, transaction: Transaction) { thumbnail.videoId = this.id @@ -1838,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 {