Move admin stuff in +admin

pull/4481/head
Chocobozzz 2021-11-02 14:14:26 +01:00
parent 047f9585dd
commit 05ac4ac7ed
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 118 additions and 96 deletions

View File

@ -33,7 +33,7 @@ import { VideoRedundancyInformationComponent } from './follows/video-redundancie
import { AbuseListComponent, VideoBlockListComponent } from './moderation'
import { InstanceAccountBlocklistComponent, InstanceServerBlocklistComponent } from './moderation/instance-blocklist'
import { VideoCommentListComponent } from './moderation/video-comment-list'
import { UserCreateComponent, UserListComponent, UserPasswordComponent, UserUpdateComponent, VideoListComponent } from './overview'
import { UserCreateComponent, UserListComponent, UserPasswordComponent, UserUpdateComponent, VideoAdminService, VideoListComponent } from './overview'
import { PluginListInstalledComponent } from './plugins/plugin-list-installed/plugin-list-installed.component'
import { PluginSearchComponent } from './plugins/plugin-search/plugin-search.component'
import { PluginShowInstalledComponent } from './plugins/plugin-show-installed/plugin-show-installed.component'
@ -116,7 +116,8 @@ import { JobsComponent } from './system/jobs/jobs.component'
DebugService,
ConfigService,
PluginApiService,
EditConfigurationService
EditConfigurationService,
VideoAdminService
]
})
export class AdminModule { }

View File

@ -1,2 +1,3 @@
export * from './video-admin.service'
export * from './video-list.component'
export * from './video.routes'

View File

@ -0,0 +1,97 @@
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 } from '@shared/models'
@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 [
{
title: $localize`Videos scope`,
children: [
{
queryParams: { search: 'isLocal:false' },
label: $localize`Remote videos`
},
{
queryParams: { search: 'isLocal:true' },
label: $localize`Local videos`
}
]
},
{
title: $localize`Include/Exclude`,
children: [
{
queryParams: { search: 'excludeMuted' },
label: $localize`Exclude muted accounts`
}
]
}
]
}
private buildAdminParamsFromSearch (search: string, params: HttpParams) {
let include = VideoInclude.BLACKLISTED |
VideoInclude.BLOCKED_OWNER |
VideoInclude.HIDDEN_PRIVACY |
VideoInclude.NOT_PUBLISHED_STATE |
VideoInclude.FILES
if (!search) return this.restService.addObjectParams(params, { include })
const filters = this.restService.parseQueryStringFilter(search, {
isLocal: {
prefix: 'isLocal:',
isBoolean: true
},
excludeMuted: {
prefix: 'excludeMuted',
handler: () => true
}
})
if (filters.excludeMuted) {
include &= ~VideoInclude.BLOCKED_OWNER
filters.excludeMuted = undefined
}
return this.restService.addObjectParams(params, { ...filters, include })
}
}

View File

@ -7,6 +7,7 @@ import { AdvancedInputFilter } from '@app/shared/shared-forms'
import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
import { VideoAdminService } from './video-admin.service'
@Component({
selector: 'my-video-list',
@ -46,7 +47,8 @@ export class VideoListComponent extends RestTable implements OnInit {
private confirmService: ConfirmService,
private auth: AuthService,
private notifier: Notifier,
private videoService: VideoService
private videoService: VideoService,
private videoAdminService: VideoAdminService
) {
super()
}
@ -58,7 +60,7 @@ export class VideoListComponent extends RestTable implements OnInit {
ngOnInit () {
this.initialize()
this.inputFilters = this.videoService.buildAdminInputFilter()
this.inputFilters = this.videoAdminService.buildAdminInputFilter()
this.bulkVideoActions = [
[
@ -128,7 +130,7 @@ export class VideoListComponent extends RestTable implements OnInit {
this.loading = true
this.videoService.getAdminVideos({
this.videoAdminService.getAdminVideos({
pagination: this.pagination,
sort: this.sort,
search: this.search

View File

@ -3,9 +3,8 @@ import { from, Observable } from 'rxjs'
import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators'
import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { ComponentPaginationLight, RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core'
import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core'
import { objectToFormData } from '@app/helpers'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
import {
BooleanBothQuery,
FeedFormat,
@ -204,27 +203,6 @@ export class VideoService {
)
}
getAdminVideos (
options: CommonVideoParams & { pagination: RestPagination, search?: string }
): Observable<ResultList<Video>> {
const { pagination, search } = options
let params = new HttpParams()
params = this.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.extractVideos(res)),
catchError(err => this.restExtractor.handleError(err))
)
}
getVideos (parameters: CommonVideoParams): Observable<ResultList<Video>> {
let params = new HttpParams()
params = this.buildCommonVideosParams({ params, ...parameters })
@ -405,21 +383,7 @@ export class VideoService {
: 'both'
}
private setVideoRate (id: number, rateType: UserVideoRateType) {
const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate`
const body: UserVideoRateUpdate = {
rating: rateType
}
return this.authHttp
.put(url, body)
.pipe(
map(this.restExtractor.extractDataBool),
catchError(err => this.restExtractor.handleError(err))
)
}
private buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) {
buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) {
const {
params,
videoPagination,
@ -453,60 +417,17 @@ export class VideoService {
return newParams
}
buildAdminInputFilter (): AdvancedInputFilter[] {
return [
{
title: $localize`Videos scope`,
children: [
{
queryParams: { search: 'isLocal:false' },
label: $localize`Remote videos`
},
{
queryParams: { search: 'isLocal:true' },
label: $localize`Local videos`
}
]
},
{
title: $localize`Include/Exclude`,
children: [
{
queryParams: { search: 'excludeMuted' },
label: $localize`Exclude muted accounts`
}
]
}
]
}
private buildAdminParamsFromSearch (search: string, params: HttpParams) {
let include = VideoInclude.BLACKLISTED |
VideoInclude.BLOCKED_OWNER |
VideoInclude.HIDDEN_PRIVACY |
VideoInclude.NOT_PUBLISHED_STATE |
VideoInclude.FILES
if (!search) return this.restService.addObjectParams(params, { include })
const filters = this.restService.parseQueryStringFilter(search, {
isLocal: {
prefix: 'isLocal:',
isBoolean: true
},
excludeMuted: {
prefix: 'excludeMuted',
handler: () => true
}
})
if (filters.excludeMuted) {
include &= ~VideoInclude.BLOCKED_OWNER
filters.excludeMuted = undefined
private setVideoRate (id: number, rateType: UserVideoRateType) {
const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate`
const body: UserVideoRateUpdate = {
rating: rateType
}
return this.restService.addObjectParams(params, { ...filters, include })
return this.authHttp
.put(url, body)
.pipe(
map(this.restExtractor.extractDataBool),
catchError(err => this.restExtractor.handleError(err))
)
}
}