From 20c72fc6d58e78f05a57884bc523d085b5369c23 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 May 2021 16:52:54 +0200 Subject: [PATCH] Support is live filter --- PeerTube | 2 +- client/src/views/Search.vue | 36 ++++++++++++++++++++++++- server/lib/elastic-search-avatar.ts | 6 ++--- server/lib/elastic-search-videos.ts | 9 +++++++ server/middlewares/validators/search.ts | 3 +++ server/types/channel.model.ts | 6 ++--- server/types/video-search.model.ts | 2 +- server/types/video.model.ts | 4 +-- 8 files changed, 57 insertions(+), 11 deletions(-) diff --git a/PeerTube b/PeerTube index 969e59d..f676e0e 160000 --- a/PeerTube +++ b/PeerTube @@ -1 +1 @@ -Subproject commit 969e59d17d584baf695cf9a7d6122283518386a7 +Subproject commit f676e0e32112821255b70018282d59207932d987 diff --git a/client/src/views/Search.vue b/client/src/views/Search.vue index d9ff813..6fd3d2d 100644 --- a/client/src/views/Search.vue +++ b/client/src/views/Search.vue @@ -49,7 +49,7 @@
-
+
@@ -69,6 +69,26 @@
+
+
+ + + +
+ +
+ + +
+ +
+ + +
+
+
@@ -344,6 +364,10 @@ margin-bottom: 5px; } + .form-group.small-height { + min-height: 30px; + } + .radio-container { display: inline-block; margin: 0 10px 5px 0; @@ -478,6 +502,8 @@ formTagsAllOf: [], formTagsOneOf: [], + formIsLive: undefined, + activeFilters: 0 } }, @@ -730,6 +756,7 @@ search: this.formSearch, sort: this.formSort, nsfw: this.formNSFW, + isLive: this.formIsLive, publishedDateRange: this.formPublishedDateRange, durationRange: this.formDurationRange, categoryOneOf: this.formCategoryOneOf, @@ -776,6 +803,9 @@ if (query.sort) this.formSort = query.sort else this.formSort = '-match' + if (query.isLive) this.formIsLive = query.isLive + else this.formIsLive = undefined + if (query.page && this.currentPage !== query.page) { this.currentPage = parseInt(query.page + '') } else { @@ -810,6 +840,8 @@ tagsOneOf: this.formTagsOneOf.map(t => t.text), tagsAllOf: this.formTagsAllOf.map(t => t.text), + isLive: this.formIsLive !== undefined ? this.formIsLive : undefined, + start, count, sort: this.formSort @@ -906,6 +938,7 @@ else if (field === 'categoryOneOf') this.formCategoryOneOf = undefined else if (field === 'licenceOneOf') this.formLicenceOneOf = undefined else if (field === 'languageOneOf') this.formLanguageOneOf = undefined + else if (field === 'isLive') this.formIsLive = undefined else if (field === 'tagsAllOf') this.formTagsAllOf = [] else if (field === 'tagsOneOf') this.formTagsOneOf = [] }, @@ -924,6 +957,7 @@ if (this.formCategoryOneOf) count++ if (this.formLicenceOneOf) count++ if (this.formLanguageOneOf) count++ + if (this.formIsLive) count++ if (this.formTagsAllOf && this.formTagsAllOf.length !== 0) count++ if (this.formTagsOneOf && this.formTagsOneOf.length !== 0) count++ diff --git a/server/lib/elastic-search-avatar.ts b/server/lib/elastic-search-avatar.ts index 2e0c93e..3df9191 100644 --- a/server/lib/elastic-search-avatar.ts +++ b/server/lib/elastic-search-avatar.ts @@ -1,8 +1,8 @@ -import { Avatar } from '@shared/models' +import { ActorImage } from '@shared/models' import { buildUrl } from '../helpers/utils' -function formatAvatarForAPI (obj: { avatar?: Avatar & { url: string } }) { +function formatAvatarForAPI (obj: { avatar?: ActorImage & { url: string } }) { if (!obj.avatar) return null return { @@ -13,7 +13,7 @@ function formatAvatarForAPI (obj: { avatar?: Avatar & { url: string } }) { } } -function formatAvatarForDB (obj: { avatar?: Avatar, host: string }) { +function formatAvatarForDB (obj: { avatar?: ActorImage, host: string }) { if (!obj.avatar) return null return { diff --git a/server/lib/elastic-search-videos.ts b/server/lib/elastic-search-videos.ts index a31053d..8cb426b 100644 --- a/server/lib/elastic-search-videos.ts +++ b/server/lib/elastic-search-videos.ts @@ -1,4 +1,5 @@ import { difference } from 'lodash' +import { exists } from '../helpers/custom-validators/misc' import { buildIndex, buildSort, elasticSearch, extractQueryResult, indexDocuments } from '../helpers/elastic-search' import { logger } from '../helpers/logger' import { buildUrl } from '../helpers/utils' @@ -252,6 +253,14 @@ async function queryVideos (search: VideosSearchQuery) { }) } + if (exists(search.isLive)) { + filter.push({ + term: { + isLive: search.isLive + } + }) + } + Object.assign(bool, { filter }) if (mustNot.length !== 0) { diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index f6520f3..1e6785c 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts @@ -48,6 +48,9 @@ const commonVideosFiltersValidator = [ check('nsfw') .optional() .custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'), + check('isLive') + .optional() + .toBoolean(), (req: express.Request, res: express.Response, next: express.NextFunction) => { if (areValidationErrors(req, res)) return diff --git a/server/types/channel.model.ts b/server/types/channel.model.ts index cd03dcb..140eef6 100644 --- a/server/types/channel.model.ts +++ b/server/types/channel.model.ts @@ -1,5 +1,5 @@ import { IndexableDoc } from './elastic-search.model' -import { VideoChannel, VideoChannelSummary, Avatar, Account } from '../../PeerTube/shared/models' +import { VideoChannel, VideoChannelSummary, ActorImage, Account } from '../../PeerTube/shared/models' export interface IndexableChannel extends VideoChannel, IndexableDoc { url: string @@ -10,9 +10,9 @@ export interface DBChannel extends Omit { handle: string url: string - ownerAccount?: Account & { handle: string, avatar: Avatar & { url: string } } + ownerAccount?: Account & { handle: string, avatar: ActorImage & { url: string } } - avatar?: Avatar & { url: string } + avatar?: ActorImage & { url: string } score?: number } diff --git a/server/types/video-search.model.ts b/server/types/video-search.model.ts index 116ea37..deda75f 100644 --- a/server/types/video-search.model.ts +++ b/server/types/video-search.model.ts @@ -1,4 +1,4 @@ -import { VideosSearchQuery as PeerTubeVideosSearchQuery} from '../../PeerTube/shared/models/search/videos-search-query.model' +import { VideosSearchQuery as PeerTubeVideosSearchQuery } from '../../PeerTube/shared/models/search/videos-search-query.model' import { CommonSearch } from './common-search.model' export type VideosSearchQuery = Omit & CommonSearch & { boostLanguages: string[] } diff --git a/server/types/video.model.ts b/server/types/video.model.ts index f663e31..5ef6249 100644 --- a/server/types/video.model.ts +++ b/server/types/video.model.ts @@ -1,10 +1,10 @@ -import { Account, AccountSummary, Avatar, Video, VideoChannel, VideoChannelSummary, VideoDetails } from '../../PeerTube/shared/models' +import { Account, AccountSummary, ActorImage, Video, VideoChannel, VideoChannelSummary, VideoDetails } from '../../PeerTube/shared/models' import { IndexableDoc } from './elastic-search.model' type ActorExtended = { handle: string - avatar: Avatar & { url: string } + avatar: ActorImage & { url: string } } export interface IndexableVideo extends Video, IndexableDoc {