X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fvideo-import%2Fvideo-import.service.ts;h=002412bd717e1c331f32732a5a659c90baa4a657;hb=ce33919c24e7402d92d81f3cd8e545df52d98240;hp=59b58ab38dffa5c727f639d85ca84212897abf85;hpb=9a12f169c15b638fe78cf6e85a1993550a25e404;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..002412bd7 100644 --- a/client/src/app/shared/video-import/video-import.service.ts +++ b/client/src/app/shared/video-import/video-import.service.ts @@ -26,8 +26,43 @@ 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 @@ -35,9 +70,7 @@ export class VideoImportService { const support = video.support || null const scheduleUpdate = video.scheduleUpdate || null - const body: VideoImportCreate = { - targetUrl, - + return { name: video.name, category, licence, @@ -54,23 +87,6 @@ export class VideoImportService { previewfile: video.previewfile, scheduleUpdate } - - 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> {