]>
Commit | Line | Data |
---|---|---|
fbad87b0 C |
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' | |
11 | ||
12 | @Injectable() | |
13 | export class VideoImportService { | |
14 | private static BASE_VIDEO_IMPORT_URL = environment.apiUrl + '/api/v1/videos/imports/' | |
15 | ||
16 | constructor ( | |
17 | private authHttp: HttpClient, | |
18 | private restService: RestService, | |
19 | private restExtractor: RestExtractor | |
20 | ) {} | |
21 | ||
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 | |
30 | ||
31 | const body: VideoImportCreate = { | |
32 | targetUrl, | |
33 | ||
34 | name: video.name, | |
35 | category, | |
36 | licence, | |
37 | language, | |
38 | support, | |
39 | description, | |
40 | channelId: video.channelId, | |
41 | privacy: video.privacy, | |
42 | tags: video.tags, | |
43 | nsfw: video.nsfw, | |
44 | waitTranscoding: video.waitTranscoding, | |
45 | commentsEnabled: video.commentsEnabled, | |
46 | thumbnailfile: video.thumbnailfile, | |
47 | previewfile: video.previewfile, | |
48 | scheduleUpdate | |
49 | } | |
50 | ||
51 | const data = objectToFormData(body) | |
52 | return this.authHttp.post<VideoImport>(url, data) | |
53 | .pipe(catchError(res => this.restExtractor.handleError(res))) | |
54 | } | |
55 | ||
56 | } |