2020-06-02 18:50:42 +00:00
|
|
|
import { SortMeta } from 'primeng/api'
|
|
|
|
import { from as observableFrom, Observable } from 'rxjs'
|
2020-06-23 12:10:17 +00:00
|
|
|
import { catchError, concatMap, map, toArray } from 'rxjs/operators'
|
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http'
|
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
import { RestExtractor, RestPagination, RestService } from '@app/core'
|
|
|
|
import { ResultList, VideoBlacklist, VideoBlacklistType } from '@shared/models'
|
2020-06-02 18:50:42 +00:00
|
|
|
import { environment } from '../../../environments/environment'
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class VideoBlockService {
|
|
|
|
private static BASE_VIDEOS_URL = environment.apiUrl + '/api/v1/videos/'
|
|
|
|
|
|
|
|
constructor (
|
|
|
|
private authHttp: HttpClient,
|
|
|
|
private restService: RestService,
|
|
|
|
private restExtractor: RestExtractor
|
|
|
|
) {}
|
|
|
|
|
|
|
|
listBlocks (options: {
|
|
|
|
pagination: RestPagination
|
|
|
|
sort: SortMeta
|
|
|
|
search?: string
|
2020-06-09 14:07:10 +00:00
|
|
|
type?: VideoBlacklistType
|
|
|
|
}): Observable<ResultList<VideoBlacklist>> {
|
2020-06-02 18:50:42 +00:00
|
|
|
const { pagination, sort, search, type } = options
|
|
|
|
|
|
|
|
let params = new HttpParams()
|
|
|
|
params = this.restService.addRestGetParams(params, pagination, sort)
|
|
|
|
|
|
|
|
if (search) {
|
|
|
|
const filters = this.restService.parseQueryStringFilter(search, {
|
|
|
|
type: {
|
|
|
|
prefix: 'type:',
|
|
|
|
handler: v => {
|
2020-06-09 14:07:10 +00:00
|
|
|
if (v === 'manual') return VideoBlacklistType.MANUAL
|
|
|
|
if (v === 'auto') return VideoBlacklistType.AUTO_BEFORE_PUBLISHED
|
2020-06-02 18:50:42 +00:00
|
|
|
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
params = this.restService.addObjectParams(params, filters)
|
|
|
|
}
|
2020-06-09 14:23:16 +00:00
|
|
|
if (type) params = params.append('type', type.toString())
|
2020-06-02 18:50:42 +00:00
|
|
|
|
2020-06-09 14:07:10 +00:00
|
|
|
return this.authHttp.get<ResultList<VideoBlacklist>>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params })
|
2020-06-02 18:50:42 +00:00
|
|
|
.pipe(
|
|
|
|
map(res => this.restExtractor.convertResultListDateToHuman(res)),
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
unblockVideo (videoIdArgs: number | number[]) {
|
|
|
|
const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ]
|
|
|
|
|
|
|
|
return observableFrom(videoIds)
|
|
|
|
.pipe(
|
|
|
|
concatMap(id => this.authHttp.delete(VideoBlockService.BASE_VIDEOS_URL + id + '/blacklist')),
|
|
|
|
toArray(),
|
|
|
|
catchError(err => this.restExtractor.handleError(err))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-11-17 10:18:49 +00:00
|
|
|
blockVideo (options: {
|
|
|
|
videoId: number
|
|
|
|
reason?: string
|
|
|
|
unfederate: boolean
|
|
|
|
}[]) {
|
|
|
|
return observableFrom(options)
|
|
|
|
.pipe(
|
|
|
|
concatMap(({ videoId, unfederate, reason }) => {
|
|
|
|
const body = { unfederate, reason }
|
2020-06-02 18:50:42 +00:00
|
|
|
|
2021-11-17 10:18:49 +00:00
|
|
|
return this.authHttp.post(VideoBlockService.BASE_VIDEOS_URL + videoId + '/blacklist', body)
|
|
|
|
}),
|
|
|
|
toArray(),
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
2020-06-02 18:50:42 +00:00
|
|
|
}
|
|
|
|
}
|