From ed31c059851a30bd5ba9999f8ecb3822d576b9f4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 2 Aug 2018 17:48:50 +0200 Subject: Add ability to list video imports --- .../shared/video-import/video-import.service.ts | 38 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'client/src/app/shared/video-import') diff --git a/client/src/app/shared/video-import/video-import.service.ts b/client/src/app/shared/video-import/video-import.service.ts index b4709866a..59b58ab38 100644 --- a/client/src/app/shared/video-import/video-import.service.ts +++ b/client/src/app/shared/video-import/video-import.service.ts @@ -1,5 +1,5 @@ -import { catchError } from 'rxjs/operators' -import { HttpClient } from '@angular/common/http' +import { catchError, map, switchMap } from 'rxjs/operators' +import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { Observable } from 'rxjs' import { VideoImport } from '../../../../../shared' @@ -8,6 +8,12 @@ import { RestExtractor, RestService } from '../rest' import { VideoImportCreate } from '../../../../../shared/models/videos/video-import-create.model' import { objectToFormData } from '@app/shared/misc/utils' import { VideoUpdate } from '../../../../../shared/models/videos' +import { ResultList } from '../../../../../shared/models/result-list.model' +import { UserService } from '@app/shared/users/user.service' +import { SortMeta } from 'primeng/components/common/sortmeta' +import { RestPagination } from '@app/shared/rest' +import { ServerService } from '@app/core' +import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' @Injectable() export class VideoImportService { @@ -16,7 +22,8 @@ export class VideoImportService { constructor ( private authHttp: HttpClient, private restService: RestService, - private restExtractor: RestExtractor + private restExtractor: RestExtractor, + private serverService: ServerService ) {} importVideo (targetUrl: string, video: VideoUpdate): Observable { @@ -53,4 +60,29 @@ export class VideoImportService { .pipe(catchError(res => this.restExtractor.handleError(res))) } + getMyVideoImports (pagination: RestPagination, sort: SortMeta): Observable> { + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + return this.authHttp + .get>(UserService.BASE_USERS_URL + '/me/videos/imports', { params }) + .pipe( + switchMap(res => this.extractVideoImports(res)), + map(res => this.restExtractor.convertResultListDateToHuman(res)), + catchError(err => this.restExtractor.handleError(err)) + ) + } + + private extractVideoImports (result: ResultList): Observable> { + return this.serverService.localeObservable + .pipe( + map(translations => { + result.data.forEach(d => + d.state.label = peertubeTranslate(d.state.label, translations) + ) + + return result + }) + ) + } } -- cgit v1.2.3