PeerTube/client/src/app/+admin/overview/videos/video-admin.service.ts

162 lines
4.3 KiB
TypeScript
Raw Normal View History

2021-11-02 14:14:26 +01:00
import { Observable } from 'rxjs'
import { catchError, switchMap } from 'rxjs/operators'
import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { RestExtractor, RestPagination, RestService } from '@app/core'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
import { CommonVideoParams, Video, VideoService } from '@app/shared/shared-main'
import { ResultList, VideoInclude, VideoPrivacy } from '@peertube/peertube-models'
import { getAllPrivacies } from '@peertube/peertube-core-utils'
2021-11-02 14:14:26 +01:00
@Injectable()
export class VideoAdminService {
constructor (
private videoService: VideoService,
private authHttp: HttpClient,
private restExtractor: RestExtractor,
private restService: RestService
) {}
getAdminVideos (
options: CommonVideoParams & { pagination: RestPagination, search?: string }
): Observable<ResultList<Video>> {
const { pagination, search } = options
let params = new HttpParams()
params = this.videoService.buildCommonVideosParams({ params, ...options })
params = params.set('start', pagination.start.toString())
.set('count', pagination.count.toString())
params = this.buildAdminParamsFromSearch(search, params)
return this.authHttp
.get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
.pipe(
switchMap(res => this.videoService.extractVideos(res)),
catchError(err => this.restExtractor.handleError(err))
)
}
buildAdminInputFilter (): AdvancedInputFilter[] {
return [
2021-11-03 09:59:53 +01:00
{
title: $localize`Video type`,
children: [
{
2021-11-03 14:23:55 +01:00
value: 'isLive:false',
2021-11-03 11:32:41 +01:00
label: $localize`VOD`
2021-11-03 09:59:53 +01:00
},
{
2021-11-03 14:23:55 +01:00
value: 'isLive:true',
2021-11-03 11:32:41 +01:00
label: $localize`Live`
}
]
},
{
title: $localize`Video files`,
children: [
{
value: 'webVideos:true isLocal:true',
label: $localize`With Web Videos`
2021-11-03 11:32:41 +01:00
},
{
value: 'webVideos:false isLocal:true',
label: $localize`Without Web Videos`
2021-11-03 11:32:41 +01:00
},
{
2021-11-25 16:24:15 +01:00
value: 'hls:true isLocal:true',
2021-11-03 11:32:41 +01:00
label: $localize`With HLS`
},
{
2021-11-25 16:24:15 +01:00
value: 'hls:false isLocal:true',
2021-11-03 11:32:41 +01:00
label: $localize`Without HLS`
2021-11-03 09:59:53 +01:00
}
]
},
2021-11-02 14:14:26 +01:00
{
title: $localize`Videos scope`,
children: [
{
2021-11-03 14:23:55 +01:00
value: 'isLocal:false',
2021-11-02 14:14:26 +01:00
label: $localize`Remote videos`
},
{
2021-11-03 14:23:55 +01:00
value: 'isLocal:true',
2021-11-02 14:14:26 +01:00
label: $localize`Local videos`
}
]
},
{
2021-11-03 11:32:41 +01:00
title: $localize`Exclude`,
2021-11-02 14:14:26 +01:00
children: [
{
2021-11-03 14:23:55 +01:00
value: 'excludeMuted',
2021-11-02 14:14:26 +01:00
label: $localize`Exclude muted accounts`
},
{
value: 'excludePublic',
label: $localize`Exclude public videos`
2021-11-02 14:14:26 +01:00
}
]
}
]
}
private buildAdminParamsFromSearch (search: string, params: HttpParams) {
let include = VideoInclude.BLACKLISTED |
VideoInclude.BLOCKED_OWNER |
VideoInclude.NOT_PUBLISHED_STATE |
VideoInclude.FILES
let privacyOneOf = getAllPrivacies()
if (!search) return this.restService.addObjectParams(params, { include, privacyOneOf })
2021-11-02 14:14:26 +01:00
const filters = this.restService.parseQueryStringFilter(search, {
isLocal: {
prefix: 'isLocal:',
isBoolean: true
},
2021-11-03 11:32:41 +01:00
hasHLSFiles: {
prefix: 'hls:',
isBoolean: true
},
hasWebVideoFiles: {
prefix: 'webVideos:',
2021-11-03 11:32:41 +01:00
isBoolean: true
},
2021-11-03 09:59:53 +01:00
isLive: {
prefix: 'isLive:',
isBoolean: true
},
2021-11-02 14:14:26 +01:00
excludeMuted: {
prefix: 'excludeMuted',
handler: () => true
},
excludePublic: {
prefix: 'excludePublic',
handler: () => true
2021-11-02 14:14:26 +01:00
}
})
if (filters.excludeMuted) {
include &= ~VideoInclude.BLOCKED_OWNER
filters.excludeMuted = undefined
}
if (filters.excludePublic) {
privacyOneOf = [ VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED, VideoPrivacy.INTERNAL, VideoPrivacy.PASSWORD_PROTECTED ]
filters.excludePublic = undefined
}
return this.restService.addObjectParams(params, { ...filters, include, privacyOneOf })
2021-11-02 14:14:26 +01:00
}
}