X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=003741da0c3b8222c9f0cef894cb5597315ff11a;hb=597f771f3f2bfe4b1e7234a5760e23f0283e2b29;hp=f9618c102fbdcd9450ba1bbd117c7586c0aee9fd;hpb=3c10840fa90fc88fc98e8169faf4745ff6c80893;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index f9618c102..003741da0 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -805,14 +805,17 @@ export class VideoModel extends Model>> { await Promise.all(tasks) } - static listLocal (): Promise { + static listLocalIds (): Promise { const query = { + attributes: [ 'id' ], + raw: true, where: { remote: false } } return VideoModel.findAll(query) + .then(rows => rows.map(r => r.id)) } static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) { @@ -1030,6 +1033,8 @@ export class VideoModel extends Model>> { include?: VideoInclude hasFiles?: boolean // default false + hasWebtorrentFiles?: boolean + hasHLSFiles?: boolean categoryOneOf?: number[] licenceOneOf?: number[] @@ -1053,9 +1058,7 @@ export class VideoModel extends Model>> { search?: string }) { - if (VideoModel.isPrivateInclude(options.include) && !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') - } + VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user) const trendingDays = options.sort.endsWith('trending') ? CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS @@ -1088,6 +1091,8 @@ export class VideoModel extends Model>> { 'videoPlaylistId', 'user', 'historyOfUser', + 'hasHLSFiles', + 'hasWebtorrentFiles', 'search' ]), @@ -1103,27 +1108,39 @@ export class VideoModel extends Model>> { start: number count: number sort: string - search?: string - host?: string - startDate?: string // ISO 8601 - endDate?: string // ISO 8601 - originallyPublishedStartDate?: string - originallyPublishedEndDate?: string + nsfw?: boolean isLive?: boolean isLocal?: boolean include?: VideoInclude + categoryOneOf?: number[] licenceOneOf?: number[] languageOneOf?: string[] tagsOneOf?: string[] tagsAllOf?: string[] + + displayOnlyForFollower: DisplayOnlyForFollowerOptions | null + + user?: MUserAccountId + + hasWebtorrentFiles?: boolean + hasHLSFiles?: boolean + + search?: string + + host?: string + startDate?: string // ISO 8601 + endDate?: string // ISO 8601 + originallyPublishedStartDate?: string + originallyPublishedEndDate?: string + durationMin?: number // seconds durationMax?: number // seconds - user?: MUserAccountId uuids?: string[] - displayOnlyForFollower: DisplayOnlyForFollowerOptions | null }) { + VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user) + const serverActor = await getServerActor() const queryOptions = { @@ -1148,6 +1165,8 @@ export class VideoModel extends Model>> { 'originallyPublishedEndDate', 'durationMin', 'durationMax', + 'hasHLSFiles', + 'hasWebtorrentFiles', 'uuids', 'search', 'displayOnlyForFollower' @@ -1489,6 +1508,12 @@ export class VideoModel extends Model>> { } } + private static throwIfPrivateIncludeWithoutUser (include: VideoInclude, user: MUserAccountId) { + if (VideoModel.isPrivateInclude(include) && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) { + throw new Error('Try to filter all-local but no user has not the see all videos right') + } + } + private static isPrivateInclude (include: VideoInclude) { return include & VideoInclude.BLACKLISTED || include & VideoInclude.BLOCKED_OWNER || @@ -1551,9 +1576,7 @@ export class VideoModel extends Model>> { if (Array.isArray(this.Thumbnails) === false) this.Thumbnails = [] - // Already have this thumbnail, skip - if (this.Thumbnails.find(t => t.id === savedThumbnail.id)) return - + this.Thumbnails = this.Thumbnails.filter(t => t.id !== savedThumbnail.id) this.Thumbnails.push(savedThumbnail) } @@ -1652,6 +1675,8 @@ export class VideoModel extends Model>> { if (!this.VideoStreamingPlaylists) return undefined const playlist = this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) + if (!playlist) return undefined + playlist.Video = this return playlist @@ -1729,8 +1754,8 @@ export class VideoModel extends Model>> { return this.hasPrivacyForFederation() === false && isPrivacyForFederation(newPrivacy) === true } - setAsRefreshed () { - return setAsUpdated('video', this.id) + setAsRefreshed (transaction?: Transaction) { + return setAsUpdated('video', this.id, transaction) } requiresAuth () { @@ -1763,7 +1788,7 @@ export class VideoModel extends Model>> { await this.save({ transaction }) } - getBandwidthBits (videoFile: MVideoFile) { + getBandwidthBits (this: MVideo, videoFile: MVideoFile) { return Math.ceil((videoFile.size * 8) / this.duration) }