X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fvideo-import%2Fvideo-import.service.ts;h=3e3fb7dfb42aeb6a60287e773da51d0f79b2058d;hb=ba430d7516bc5b1324b60571ba7594460969b7fb;hp=59b58ab38dffa5c727f639d85ca84212897abf85;hpb=3d52b300ea79bec21f090e2447c4808307078618;p=github%2FChocobozzz%2FPeerTube.git 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 59b58ab38..3e3fb7dfb 100644 --- a/client/src/app/shared/video-import/video-import.service.ts +++ b/client/src/app/shared/video-import/video-import.service.ts @@ -2,18 +2,16 @@ 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' +import { peertubeTranslate, VideoImport } from '../../../../../shared' import { environment } from '../../../environments/environment' import { RestExtractor, RestService } from '../rest' -import { VideoImportCreate } from '../../../../../shared/models/videos/video-import-create.model' +import { VideoImportCreate, VideoUpdate } from '../../../../../shared/models/videos' 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 { @@ -26,18 +24,52 @@ export class VideoImportService { private serverService: ServerService ) {} - importVideo (targetUrl: string, video: VideoUpdate): Observable { + importVideoUrl (targetUrl: string, video: VideoUpdate): Observable { const url = VideoImportService.BASE_VIDEO_IMPORT_URL + + const body = this.buildImportVideoObject(video) + body.targetUrl = targetUrl + + const data = objectToFormData(body) + return this.authHttp.post(url, data) + .pipe(catchError(res => this.restExtractor.handleError(res))) + } + + importVideoTorrent (target: string | Blob, video: VideoUpdate): Observable { + const url = VideoImportService.BASE_VIDEO_IMPORT_URL + const body: VideoImportCreate = this.buildImportVideoObject(video) + + if (typeof target === 'string') body.magnetUri = target + else body.torrentfile = target + + const data = objectToFormData(body) + return this.authHttp.post(url, data) + .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 buildImportVideoObject (video: VideoUpdate): VideoImportCreate { const language = video.language || null const licence = video.licence || null const category = video.category || null const description = video.description || null const support = video.support || null const scheduleUpdate = video.scheduleUpdate || null + const originallyPublishedAt = video.originallyPublishedAt || null - const body: VideoImportCreate = { - targetUrl, - + return { name: video.name, category, licence, @@ -50,31 +82,16 @@ export class VideoImportService { nsfw: video.nsfw, waitTranscoding: video.waitTranscoding, commentsEnabled: video.commentsEnabled, + downloadEnabled: video.downloadEnabled, thumbnailfile: video.thumbnailfile, previewfile: video.previewfile, - scheduleUpdate + scheduleUpdate, + originallyPublishedAt } - - const data = objectToFormData(body) - return this.authHttp.post(url, data) - .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 + return this.serverService.getServerLocale() .pipe( map(translations => { result.data.forEach(d =>