diff options
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/video-import/video-import.service.ts | 58 |
1 files changed, 37 insertions, 21 deletions
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 { | |||
26 | private serverService: ServerService | 26 | private serverService: ServerService |
27 | ) {} | 27 | ) {} |
28 | 28 | ||
29 | importVideo (targetUrl: string, video: VideoUpdate): Observable<VideoImport> { | 29 | importVideoUrl (targetUrl: string, video: VideoUpdate): Observable<VideoImport> { |
30 | const url = VideoImportService.BASE_VIDEO_IMPORT_URL | 30 | const url = VideoImportService.BASE_VIDEO_IMPORT_URL |
31 | |||
32 | const body = this.buildImportVideoObject(video) | ||
33 | body.targetUrl = targetUrl | ||
34 | |||
35 | const data = objectToFormData(body) | ||
36 | return this.authHttp.post<VideoImport>(url, data) | ||
37 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
38 | } | ||
39 | |||
40 | importVideoTorrent (target: string | Blob, video: VideoUpdate): Observable<VideoImport> { | ||
41 | const url = VideoImportService.BASE_VIDEO_IMPORT_URL | ||
42 | const body: VideoImportCreate = this.buildImportVideoObject(video) | ||
43 | |||
44 | if (typeof target === 'string') body.magnetUri = target | ||
45 | else body.torrentfile = target | ||
46 | |||
47 | const data = objectToFormData(body) | ||
48 | return this.authHttp.post<VideoImport>(url, data) | ||
49 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
50 | } | ||
51 | |||
52 | getMyVideoImports (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoImport>> { | ||
53 | let params = new HttpParams() | ||
54 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
55 | |||
56 | return this.authHttp | ||
57 | .get<ResultList<VideoImport>>(UserService.BASE_USERS_URL + '/me/videos/imports', { params }) | ||
58 | .pipe( | ||
59 | switchMap(res => this.extractVideoImports(res)), | ||
60 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
61 | catchError(err => this.restExtractor.handleError(err)) | ||
62 | ) | ||
63 | } | ||
64 | |||
65 | private buildImportVideoObject (video: VideoUpdate): VideoImportCreate { | ||
31 | const language = video.language || null | 66 | const language = video.language || null |
32 | const licence = video.licence || null | 67 | const licence = video.licence || null |
33 | const category = video.category || null | 68 | const category = video.category || null |
@@ -35,9 +70,7 @@ export class VideoImportService { | |||
35 | const support = video.support || null | 70 | const support = video.support || null |
36 | const scheduleUpdate = video.scheduleUpdate || null | 71 | const scheduleUpdate = video.scheduleUpdate || null |
37 | 72 | ||
38 | const body: VideoImportCreate = { | 73 | return { |
39 | targetUrl, | ||
40 | |||
41 | name: video.name, | 74 | name: video.name, |
42 | category, | 75 | category, |
43 | licence, | 76 | licence, |
@@ -54,23 +87,6 @@ export class VideoImportService { | |||
54 | previewfile: video.previewfile, | 87 | previewfile: video.previewfile, |
55 | scheduleUpdate | 88 | scheduleUpdate |
56 | } | 89 | } |
57 | |||
58 | const data = objectToFormData(body) | ||
59 | return this.authHttp.post<VideoImport>(url, data) | ||
60 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
61 | } | ||
62 | |||
63 | getMyVideoImports (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoImport>> { | ||
64 | let params = new HttpParams() | ||
65 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
66 | |||
67 | return this.authHttp | ||
68 | .get<ResultList<VideoImport>>(UserService.BASE_USERS_URL + '/me/videos/imports', { params }) | ||
69 | .pipe( | ||
70 | switchMap(res => this.extractVideoImports(res)), | ||
71 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
72 | catchError(err => this.restExtractor.handleError(err)) | ||
73 | ) | ||
74 | } | 90 | } |
75 | 91 | ||
76 | private extractVideoImports (result: ResultList<VideoImport>): Observable<ResultList<VideoImport>> { | 92 | private extractVideoImports (result: ResultList<VideoImport>): Observable<ResultList<VideoImport>> { |