From 05ac4ac7ed5107ac8ef1d0d1f9fd5009bf29bedc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 2 Nov 2021 14:14:26 +0100 Subject: Move admin stuff in +admin --- client/src/app/+admin/admin.module.ts | 5 +- client/src/app/+admin/overview/videos/index.ts | 1 + .../+admin/overview/videos/video-admin.service.ts | 97 ++++++++++++++++++++++ .../+admin/overview/videos/video-list.component.ts | 8 +- 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 client/src/app/+admin/overview/videos/video-admin.service.ts (limited to 'client/src/app/+admin') diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index 0cb4d1056..3606fc6ea 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts @@ -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 { } diff --git a/client/src/app/+admin/overview/videos/index.ts b/client/src/app/+admin/overview/videos/index.ts index 40c2ffe72..7398b1663 100644 --- a/client/src/app/+admin/overview/videos/index.ts +++ b/client/src/app/+admin/overview/videos/index.ts @@ -1,2 +1,3 @@ +export * from './video-admin.service' export * from './video-list.component' export * from './video.routes' diff --git a/client/src/app/+admin/overview/videos/video-admin.service.ts b/client/src/app/+admin/overview/videos/video-admin.service.ts new file mode 100644 index 000000000..696609cb2 --- /dev/null +++ b/client/src/app/+admin/overview/videos/video-admin.service.ts @@ -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> { + 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>(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 }) + } +} diff --git a/client/src/app/+admin/overview/videos/video-list.component.ts b/client/src/app/+admin/overview/videos/video-list.component.ts index 31bf1707b..b0e476569 100644 --- a/client/src/app/+admin/overview/videos/video-list.component.ts +++ b/client/src/app/+admin/overview/videos/video-list.component.ts @@ -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 -- cgit v1.2.3