Filter by category (#720)
* get videos with specific category (api) * update api doc with category * add url parameter to filter by category * fix lint issues
This commit is contained in:
parent
adc236fee3
commit
61b909b9bf
8 changed files with 30 additions and 9 deletions
|
@ -24,6 +24,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
|
||||||
totalItems: null
|
totalItems: null
|
||||||
}
|
}
|
||||||
sort: VideoSortField = '-publishedAt'
|
sort: VideoSortField = '-publishedAt'
|
||||||
|
category?: number
|
||||||
defaultSort: VideoSortField = '-publishedAt'
|
defaultSort: VideoSortField = '-publishedAt'
|
||||||
syndicationItems = []
|
syndicationItems = []
|
||||||
|
|
||||||
|
@ -167,7 +168,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
|
||||||
|
|
||||||
protected loadRouteParams (routeParams: { [ key: string ]: any }) {
|
protected loadRouteParams (routeParams: { [ key: string ]: any }) {
|
||||||
this.sort = routeParams['sort'] as VideoSortField || this.defaultSort
|
this.sort = routeParams['sort'] as VideoSortField || this.defaultSort
|
||||||
|
this.category = routeParams['category']
|
||||||
if (routeParams['page'] !== undefined) {
|
if (routeParams['page'] !== undefined) {
|
||||||
this.pagination.currentPage = parseInt(routeParams['page'], 10)
|
this.pagination.currentPage = parseInt(routeParams['page'], 10)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -158,7 +158,8 @@ export class VideoService {
|
||||||
getVideos (
|
getVideos (
|
||||||
videoPagination: ComponentPagination,
|
videoPagination: ComponentPagination,
|
||||||
sort: VideoSortField,
|
sort: VideoSortField,
|
||||||
filter?: VideoFilter
|
filter?: VideoFilter,
|
||||||
|
category?: number
|
||||||
): Observable<{ videos: Video[], totalVideos: number }> {
|
): Observable<{ videos: Video[], totalVideos: number }> {
|
||||||
const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
|
const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
|
||||||
|
|
||||||
|
@ -169,6 +170,10 @@ export class VideoService {
|
||||||
params = params.set('filter', filter)
|
params = params.set('filter', filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (category) {
|
||||||
|
params = params.set('category', category + '')
|
||||||
|
}
|
||||||
|
|
||||||
return this.authHttp
|
return this.authHttp
|
||||||
.get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
|
.get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
|
||||||
.pipe(
|
.pipe(
|
||||||
|
@ -202,11 +207,13 @@ export class VideoService {
|
||||||
return feeds
|
return feeds
|
||||||
}
|
}
|
||||||
|
|
||||||
getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter) {
|
getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter, category?: number) {
|
||||||
let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort)
|
let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort)
|
||||||
|
|
||||||
if (filter) params = params.set('filter', filter)
|
if (filter) params = params.set('filter', filter)
|
||||||
|
|
||||||
|
if (category) params = params.set('category', category + '')
|
||||||
|
|
||||||
return this.buildBaseFeedUrls(params)
|
return this.buildBaseFeedUrls(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,10 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On
|
||||||
getVideosObservable (page: number) {
|
getVideosObservable (page: number) {
|
||||||
const newPagination = immutableAssign(this.pagination, { currentPage: page })
|
const newPagination = immutableAssign(this.pagination, { currentPage: page })
|
||||||
|
|
||||||
return this.videoService.getVideos(newPagination, this.sort, this.filter)
|
return this.videoService.getVideos(newPagination, this.sort, this.filter, this.category)
|
||||||
}
|
}
|
||||||
|
|
||||||
generateSyndicationList () {
|
generateSyndicationList () {
|
||||||
this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter)
|
this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter, this.category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On
|
||||||
getVideosObservable (page: number) {
|
getVideosObservable (page: number) {
|
||||||
const newPagination = immutableAssign(this.pagination, { currentPage: page })
|
const newPagination = immutableAssign(this.pagination, { currentPage: page })
|
||||||
|
|
||||||
return this.videoService.getVideos(newPagination, this.sort)
|
return this.videoService.getVideos(newPagination, this.sort, undefined, this.category)
|
||||||
}
|
}
|
||||||
|
|
||||||
generateSyndicationList () {
|
generateSyndicationList () {
|
||||||
this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort)
|
this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,10 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit,
|
||||||
|
|
||||||
getVideosObservable (page: number) {
|
getVideosObservable (page: number) {
|
||||||
const newPagination = immutableAssign(this.pagination, { currentPage: page })
|
const newPagination = immutableAssign(this.pagination, { currentPage: page })
|
||||||
return this.videoService.getVideos(newPagination, this.sort)
|
return this.videoService.getVideos(newPagination, this.sort, undefined, this.category)
|
||||||
}
|
}
|
||||||
|
|
||||||
generateSyndicationList () {
|
generateSyndicationList () {
|
||||||
this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort)
|
this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,6 +407,7 @@ async function listVideos (req: express.Request, res: express.Response, next: ex
|
||||||
start: req.query.start,
|
start: req.query.start,
|
||||||
count: req.query.count,
|
count: req.query.count,
|
||||||
sort: req.query.sort,
|
sort: req.query.sort,
|
||||||
|
category: req.query.category,
|
||||||
hideNSFW: isNSFWHidden(res),
|
hideNSFW: isNSFWHidden(res),
|
||||||
filter: req.query.filter as VideoFilter,
|
filter: req.query.filter as VideoFilter,
|
||||||
withFiles: false
|
withFiles: false
|
||||||
|
|
|
@ -106,6 +106,7 @@ export enum ScopeNames {
|
||||||
actorId: number,
|
actorId: number,
|
||||||
hideNSFW: boolean,
|
hideNSFW: boolean,
|
||||||
filter?: VideoFilter,
|
filter?: VideoFilter,
|
||||||
|
category?: number,
|
||||||
withFiles?: boolean,
|
withFiles?: boolean,
|
||||||
accountId?: number,
|
accountId?: number,
|
||||||
videoChannelId?: number
|
videoChannelId?: number
|
||||||
|
@ -215,6 +216,10 @@ export enum ScopeNames {
|
||||||
query.where['nsfw'] = false
|
query.where['nsfw'] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.category) {
|
||||||
|
query.where['category'] = options.category
|
||||||
|
}
|
||||||
|
|
||||||
if (options.accountId) {
|
if (options.accountId) {
|
||||||
accountInclude.where = {
|
accountInclude.where = {
|
||||||
id: options.accountId
|
id: options.accountId
|
||||||
|
@ -730,6 +735,7 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
sort: string,
|
sort: string,
|
||||||
hideNSFW: boolean,
|
hideNSFW: boolean,
|
||||||
withFiles: boolean,
|
withFiles: boolean,
|
||||||
|
category?: number,
|
||||||
filter?: VideoFilter,
|
filter?: VideoFilter,
|
||||||
accountId?: number,
|
accountId?: number,
|
||||||
videoChannelId?: number
|
videoChannelId?: number
|
||||||
|
@ -746,6 +752,7 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
ScopeNames.AVAILABLE_FOR_LIST, {
|
ScopeNames.AVAILABLE_FOR_LIST, {
|
||||||
actorId: serverActor.id,
|
actorId: serverActor.id,
|
||||||
hideNSFW: options.hideNSFW,
|
hideNSFW: options.hideNSFW,
|
||||||
|
category: options.category,
|
||||||
filter: options.filter,
|
filter: options.filter,
|
||||||
withFiles: options.withFiles,
|
withFiles: options.withFiles,
|
||||||
accountId: options.accountId,
|
accountId: options.accountId,
|
||||||
|
|
|
@ -529,6 +529,11 @@ paths:
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: category
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
description: category id of the video
|
||||||
- name: start
|
- name: start
|
||||||
in: query
|
in: query
|
||||||
required: false
|
required: false
|
||||||
|
|
Loading…
Reference in a new issue