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'
|
2021-11-12 14:19:56 +01:00
|
|
|
import { ResultList, VideoInclude, VideoPrivacy } from '@shared/models'
|
|
|
|
import { getAllPrivacies } from '@shared/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: [
|
|
|
|
{
|
2021-11-03 14:23:55 +01:00
|
|
|
value: 'webtorrent:true',
|
2021-11-03 11:32:41 +01:00
|
|
|
label: $localize`With WebTorrent`
|
|
|
|
},
|
|
|
|
{
|
2021-11-03 14:23:55 +01:00
|
|
|
value: 'webtorrent:false',
|
2021-11-03 11:32:41 +01:00
|
|
|
label: $localize`Without WebTorrent`
|
|
|
|
},
|
|
|
|
{
|
2021-11-03 14:23:55 +01:00
|
|
|
value: 'hls:true',
|
2021-11-03 11:32:41 +01:00
|
|
|
label: $localize`With HLS`
|
|
|
|
},
|
|
|
|
{
|
2021-11-03 14:23:55 +01:00
|
|
|
value: 'hls:false',
|
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`
|
2021-11-12 14:19:56 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
2021-11-12 14:19:56 +01:00
|
|
|
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
|
|
|
|
},
|
|
|
|
hasWebtorrentFiles: {
|
|
|
|
prefix: 'webtorrent:',
|
|
|
|
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
|
2021-11-12 14:19:56 +01:00
|
|
|
},
|
|
|
|
excludePublic: {
|
|
|
|
prefix: 'excludePublic',
|
|
|
|
handler: () => true
|
2021-11-02 14:14:26 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (filters.excludeMuted) {
|
|
|
|
include &= ~VideoInclude.BLOCKED_OWNER
|
|
|
|
|
|
|
|
filters.excludeMuted = undefined
|
|
|
|
}
|
|
|
|
|
2021-11-12 14:19:56 +01:00
|
|
|
if (filters.excludePublic) {
|
|
|
|
privacyOneOf = [ VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED, VideoPrivacy.INTERNAL ]
|
|
|
|
|
|
|
|
filters.excludePublic = undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.restService.addObjectParams(params, { ...filters, include, privacyOneOf })
|
2021-11-02 14:14:26 +01:00
|
|
|
}
|
|
|
|
}
|