1 import { catchError } from 'rxjs/operators'
2 import { HttpClient } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { Observable } from 'rxjs'
5 import { VideoImport } from '../../../../../shared'
6 import { environment } from '../../../environments/environment'
7 import { RestExtractor, RestService } from '../rest'
8 import { VideoImportCreate } from '../../../../../shared/models/videos/video-import-create.model'
9 import { objectToFormData } from '@app/shared/misc/utils'
10 import { VideoUpdate } from '../../../../../shared/models/videos'
13 export class VideoImportService {
14 private static BASE_VIDEO_IMPORT_URL = environment.apiUrl + '/api/v1/videos/imports/'
17 private authHttp: HttpClient,
18 private restService: RestService,
19 private restExtractor: RestExtractor
22 importVideo (targetUrl: string, video: VideoUpdate): Observable<VideoImport> {
23 const url = VideoImportService.BASE_VIDEO_IMPORT_URL
24 const language = video.language || null
25 const licence = video.licence || null
26 const category = video.category || null
27 const description = video.description || null
28 const support = video.support || null
29 const scheduleUpdate = video.scheduleUpdate || null
31 const body: VideoImportCreate = {
40 channelId: video.channelId,
41 privacy: video.privacy,
44 waitTranscoding: video.waitTranscoding,
45 commentsEnabled: video.commentsEnabled,
46 thumbnailfile: video.thumbnailfile,
47 previewfile: video.previewfile,
51 const data = objectToFormData(body)
52 return this.authHttp.post<VideoImport>(url, data)
53 .pipe(catchError(res => this.restExtractor.handleError(res)))