From d324756edb836672f12284cd18e642a658b273d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Nov 2021 11:32:41 +0100 Subject: Add ability to filter by file type --- server/models/video/video.ts | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'server/models/video/video.ts') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index f9618c102..aef4fd20a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1030,6 +1030,8 @@ export class VideoModel extends Model>> { include?: VideoInclude hasFiles?: boolean // default false + hasWebtorrentFiles?: boolean + hasHLSFiles?: boolean categoryOneOf?: number[] licenceOneOf?: number[] @@ -1053,9 +1055,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 +1088,8 @@ export class VideoModel extends Model>> { 'videoPlaylistId', 'user', 'historyOfUser', + 'hasHLSFiles', + 'hasWebtorrentFiles', 'search' ]), @@ -1103,27 +1105,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 +1162,8 @@ export class VideoModel extends Model>> { 'originallyPublishedEndDate', 'durationMin', 'durationMax', + 'hasHLSFiles', + 'hasWebtorrentFiles', 'uuids', 'search', 'displayOnlyForFollower' @@ -1489,6 +1505,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 || -- cgit v1.2.3