diff options
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r-- | client/src/app/shared/shared-main/video/video.service.ts | 103 |
1 files changed, 12 insertions, 91 deletions
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index b7c563dca..6edcc3fe0 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts | |||
@@ -3,9 +3,8 @@ import { from, Observable } from 'rxjs' | |||
3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' | 3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' |
4 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' | 4 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' |
5 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { ComponentPaginationLight, RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core' | 6 | import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' |
7 | import { objectToFormData } from '@app/helpers' | 7 | import { objectToFormData } from '@app/helpers' |
8 | import { AdvancedInputFilter } from '@app/shared/shared-forms' | ||
9 | import { | 8 | import { |
10 | BooleanBothQuery, | 9 | BooleanBothQuery, |
11 | FeedFormat, | 10 | FeedFormat, |
@@ -204,27 +203,6 @@ export class VideoService { | |||
204 | ) | 203 | ) |
205 | } | 204 | } |
206 | 205 | ||
207 | getAdminVideos ( | ||
208 | options: CommonVideoParams & { pagination: RestPagination, search?: string } | ||
209 | ): Observable<ResultList<Video>> { | ||
210 | const { pagination, search } = options | ||
211 | |||
212 | let params = new HttpParams() | ||
213 | params = this.buildCommonVideosParams({ params, ...options }) | ||
214 | |||
215 | params = params.set('start', pagination.start.toString()) | ||
216 | .set('count', pagination.count.toString()) | ||
217 | |||
218 | params = this.buildAdminParamsFromSearch(search, params) | ||
219 | |||
220 | return this.authHttp | ||
221 | .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params }) | ||
222 | .pipe( | ||
223 | switchMap(res => this.extractVideos(res)), | ||
224 | catchError(err => this.restExtractor.handleError(err)) | ||
225 | ) | ||
226 | } | ||
227 | |||
228 | getVideos (parameters: CommonVideoParams): Observable<ResultList<Video>> { | 206 | getVideos (parameters: CommonVideoParams): Observable<ResultList<Video>> { |
229 | let params = new HttpParams() | 207 | let params = new HttpParams() |
230 | params = this.buildCommonVideosParams({ params, ...parameters }) | 208 | params = this.buildCommonVideosParams({ params, ...parameters }) |
@@ -405,21 +383,7 @@ export class VideoService { | |||
405 | : 'both' | 383 | : 'both' |
406 | } | 384 | } |
407 | 385 | ||
408 | private setVideoRate (id: number, rateType: UserVideoRateType) { | 386 | buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) { |
409 | const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate` | ||
410 | const body: UserVideoRateUpdate = { | ||
411 | rating: rateType | ||
412 | } | ||
413 | |||
414 | return this.authHttp | ||
415 | .put(url, body) | ||
416 | .pipe( | ||
417 | map(this.restExtractor.extractDataBool), | ||
418 | catchError(err => this.restExtractor.handleError(err)) | ||
419 | ) | ||
420 | } | ||
421 | |||
422 | private buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) { | ||
423 | const { | 387 | const { |
424 | params, | 388 | params, |
425 | videoPagination, | 389 | videoPagination, |
@@ -453,60 +417,17 @@ export class VideoService { | |||
453 | return newParams | 417 | return newParams |
454 | } | 418 | } |
455 | 419 | ||
456 | buildAdminInputFilter (): AdvancedInputFilter[] { | 420 | private setVideoRate (id: number, rateType: UserVideoRateType) { |
457 | return [ | 421 | const url = `${VideoService.BASE_VIDEO_URL}/${id}/rate` |
458 | { | 422 | const body: UserVideoRateUpdate = { |
459 | title: $localize`Videos scope`, | 423 | rating: rateType |
460 | children: [ | ||
461 | { | ||
462 | queryParams: { search: 'isLocal:false' }, | ||
463 | label: $localize`Remote videos` | ||
464 | }, | ||
465 | { | ||
466 | queryParams: { search: 'isLocal:true' }, | ||
467 | label: $localize`Local videos` | ||
468 | } | ||
469 | ] | ||
470 | }, | ||
471 | |||
472 | { | ||
473 | title: $localize`Include/Exclude`, | ||
474 | children: [ | ||
475 | { | ||
476 | queryParams: { search: 'excludeMuted' }, | ||
477 | label: $localize`Exclude muted accounts` | ||
478 | } | ||
479 | ] | ||
480 | } | ||
481 | ] | ||
482 | } | ||
483 | |||
484 | private buildAdminParamsFromSearch (search: string, params: HttpParams) { | ||
485 | let include = VideoInclude.BLACKLISTED | | ||
486 | VideoInclude.BLOCKED_OWNER | | ||
487 | VideoInclude.HIDDEN_PRIVACY | | ||
488 | VideoInclude.NOT_PUBLISHED_STATE | | ||
489 | VideoInclude.FILES | ||
490 | |||
491 | if (!search) return this.restService.addObjectParams(params, { include }) | ||
492 | |||
493 | const filters = this.restService.parseQueryStringFilter(search, { | ||
494 | isLocal: { | ||
495 | prefix: 'isLocal:', | ||
496 | isBoolean: true | ||
497 | }, | ||
498 | excludeMuted: { | ||
499 | prefix: 'excludeMuted', | ||
500 | handler: () => true | ||
501 | } | ||
502 | }) | ||
503 | |||
504 | if (filters.excludeMuted) { | ||
505 | include &= ~VideoInclude.BLOCKED_OWNER | ||
506 | |||
507 | filters.excludeMuted = undefined | ||
508 | } | 424 | } |
509 | 425 | ||
510 | return this.restService.addObjectParams(params, { ...filters, include }) | 426 | return this.authHttp |
427 | .put(url, body) | ||
428 | .pipe( | ||
429 | map(this.restExtractor.extractDataBool), | ||
430 | catchError(err => this.restExtractor.handleError(err)) | ||
431 | ) | ||
511 | } | 432 | } |
512 | } | 433 | } |