diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/video-import | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/video-import')
-rw-r--r-- | client/src/app/shared/video-import/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/video-import/video-import.service.ts | 105 |
2 files changed, 0 insertions, 106 deletions
diff --git a/client/src/app/shared/video-import/index.ts b/client/src/app/shared/video-import/index.ts deleted file mode 100644 index 9bb73ec2c..000000000 --- a/client/src/app/shared/video-import/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './video-import.service' | ||
diff --git a/client/src/app/shared/video-import/video-import.service.ts b/client/src/app/shared/video-import/video-import.service.ts deleted file mode 100644 index afd9e3fb5..000000000 --- a/client/src/app/shared/video-import/video-import.service.ts +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | import { catchError, map, switchMap } from 'rxjs/operators' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { Observable } from 'rxjs' | ||
5 | import { peertubeTranslate, VideoImport } from '../../../../../shared' | ||
6 | import { environment } from '../../../environments/environment' | ||
7 | import { RestExtractor, RestService } from '../rest' | ||
8 | import { VideoImportCreate, VideoUpdate } from '../../../../../shared/models/videos' | ||
9 | import { objectToFormData } from '@app/shared/misc/utils' | ||
10 | import { ResultList } from '../../../../../shared/models/result-list.model' | ||
11 | import { UserService } from '@app/shared/users/user.service' | ||
12 | import { SortMeta } from 'primeng/api' | ||
13 | import { RestPagination } from '@app/shared/rest' | ||
14 | import { ServerService } from '@app/core' | ||
15 | |||
16 | @Injectable() | ||
17 | export class VideoImportService { | ||
18 | private static BASE_VIDEO_IMPORT_URL = environment.apiUrl + '/api/v1/videos/imports/' | ||
19 | |||
20 | constructor ( | ||
21 | private authHttp: HttpClient, | ||
22 | private restService: RestService, | ||
23 | private restExtractor: RestExtractor, | ||
24 | private serverService: ServerService | ||
25 | ) {} | ||
26 | |||
27 | importVideoUrl (targetUrl: string, video: VideoUpdate): Observable<VideoImport> { | ||
28 | const url = VideoImportService.BASE_VIDEO_IMPORT_URL | ||
29 | |||
30 | const body = this.buildImportVideoObject(video) | ||
31 | body.targetUrl = targetUrl | ||
32 | |||
33 | const data = objectToFormData(body) | ||
34 | return this.authHttp.post<VideoImport>(url, data) | ||
35 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
36 | } | ||
37 | |||
38 | importVideoTorrent (target: string | Blob, video: VideoUpdate): Observable<VideoImport> { | ||
39 | const url = VideoImportService.BASE_VIDEO_IMPORT_URL | ||
40 | const body: VideoImportCreate = this.buildImportVideoObject(video) | ||
41 | |||
42 | if (typeof target === 'string') body.magnetUri = target | ||
43 | else body.torrentfile = target | ||
44 | |||
45 | const data = objectToFormData(body) | ||
46 | return this.authHttp.post<VideoImport>(url, data) | ||
47 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
48 | } | ||
49 | |||
50 | getMyVideoImports (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoImport>> { | ||
51 | let params = new HttpParams() | ||
52 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
53 | |||
54 | return this.authHttp | ||
55 | .get<ResultList<VideoImport>>(UserService.BASE_USERS_URL + '/me/videos/imports', { params }) | ||
56 | .pipe( | ||
57 | switchMap(res => this.extractVideoImports(res)), | ||
58 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
59 | catchError(err => this.restExtractor.handleError(err)) | ||
60 | ) | ||
61 | } | ||
62 | |||
63 | private buildImportVideoObject (video: VideoUpdate): VideoImportCreate { | ||
64 | const language = video.language || null | ||
65 | const licence = video.licence || null | ||
66 | const category = video.category || null | ||
67 | const description = video.description || null | ||
68 | const support = video.support || null | ||
69 | const scheduleUpdate = video.scheduleUpdate || null | ||
70 | const originallyPublishedAt = video.originallyPublishedAt || null | ||
71 | |||
72 | return { | ||
73 | name: video.name, | ||
74 | category, | ||
75 | licence, | ||
76 | language, | ||
77 | support, | ||
78 | description, | ||
79 | channelId: video.channelId, | ||
80 | privacy: video.privacy, | ||
81 | tags: video.tags, | ||
82 | nsfw: video.nsfw, | ||
83 | waitTranscoding: video.waitTranscoding, | ||
84 | commentsEnabled: video.commentsEnabled, | ||
85 | downloadEnabled: video.downloadEnabled, | ||
86 | thumbnailfile: video.thumbnailfile, | ||
87 | previewfile: video.previewfile, | ||
88 | scheduleUpdate, | ||
89 | originallyPublishedAt | ||
90 | } | ||
91 | } | ||
92 | |||
93 | private extractVideoImports (result: ResultList<VideoImport>): Observable<ResultList<VideoImport>> { | ||
94 | return this.serverService.getServerLocale() | ||
95 | .pipe( | ||
96 | map(translations => { | ||
97 | result.data.forEach(d => | ||
98 | d.state.label = peertubeTranslate(d.state.label, translations) | ||
99 | ) | ||
100 | |||
101 | return result | ||
102 | }) | ||
103 | ) | ||
104 | } | ||
105 | } | ||