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-caption | |
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-caption')
3 files changed, 0 insertions, 86 deletions
diff --git a/client/src/app/shared/video-caption/index.ts b/client/src/app/shared/video-caption/index.ts deleted file mode 100644 index c48a70558..000000000 --- a/client/src/app/shared/video-caption/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './video-caption.service' | ||
diff --git a/client/src/app/shared/video-caption/video-caption-edit.model.ts b/client/src/app/shared/video-caption/video-caption-edit.model.ts deleted file mode 100644 index 732f20158..000000000 --- a/client/src/app/shared/video-caption/video-caption-edit.model.ts +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | export interface VideoCaptionEdit { | ||
2 | language: { | ||
3 | id: string | ||
4 | label?: string | ||
5 | } | ||
6 | |||
7 | action?: 'CREATE' | 'REMOVE' | ||
8 | captionfile?: any | ||
9 | } | ||
diff --git a/client/src/app/shared/video-caption/video-caption.service.ts b/client/src/app/shared/video-caption/video-caption.service.ts deleted file mode 100644 index 6bfe67435..000000000 --- a/client/src/app/shared/video-caption/video-caption.service.ts +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | import { catchError, map, switchMap } from 'rxjs/operators' | ||
2 | import { HttpClient } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { Observable, of } from 'rxjs' | ||
5 | import { peertubeTranslate, ResultList } from '../../../../../shared' | ||
6 | import { RestExtractor } from '../rest' | ||
7 | import { VideoService } from '@app/shared/video/video.service' | ||
8 | import { objectToFormData, sortBy } from '@app/shared/misc/utils' | ||
9 | import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' | ||
10 | import { VideoCaption } from '../../../../../shared/models/videos/caption/video-caption.model' | ||
11 | import { ServerService } from '@app/core' | ||
12 | |||
13 | @Injectable() | ||
14 | export class VideoCaptionService { | ||
15 | constructor ( | ||
16 | private authHttp: HttpClient, | ||
17 | private serverService: ServerService, | ||
18 | private restExtractor: RestExtractor | ||
19 | ) {} | ||
20 | |||
21 | listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> { | ||
22 | return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions') | ||
23 | .pipe( | ||
24 | switchMap(captionsResult => { | ||
25 | return this.serverService.getServerLocale() | ||
26 | .pipe(map(translations => ({ captionsResult, translations }))) | ||
27 | }), | ||
28 | map(({ captionsResult, translations }) => { | ||
29 | for (const c of captionsResult.data) { | ||
30 | c.language.label = peertubeTranslate(c.language.label, translations) | ||
31 | } | ||
32 | |||
33 | return captionsResult | ||
34 | }), | ||
35 | map(captionsResult => { | ||
36 | sortBy(captionsResult.data, 'language', 'label') | ||
37 | |||
38 | return captionsResult | ||
39 | }) | ||
40 | ) | ||
41 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
42 | } | ||
43 | |||
44 | removeCaption (videoId: number | string, language: string) { | ||
45 | return this.authHttp.delete(VideoService.BASE_VIDEO_URL + videoId + '/captions/' + language) | ||
46 | .pipe( | ||
47 | map(this.restExtractor.extractDataBool), | ||
48 | catchError(res => this.restExtractor.handleError(res)) | ||
49 | ) | ||
50 | } | ||
51 | |||
52 | addCaption (videoId: number | string, language: string, captionfile: File) { | ||
53 | const body = { captionfile } | ||
54 | const data = objectToFormData(body) | ||
55 | |||
56 | return this.authHttp.put(VideoService.BASE_VIDEO_URL + videoId + '/captions/' + language, data) | ||
57 | .pipe( | ||
58 | map(this.restExtractor.extractDataBool), | ||
59 | catchError(res => this.restExtractor.handleError(res)) | ||
60 | ) | ||
61 | } | ||
62 | |||
63 | updateCaptions (videoId: number | string, videoCaptions: VideoCaptionEdit[]) { | ||
64 | let obs = of(true) | ||
65 | |||
66 | for (const videoCaption of videoCaptions) { | ||
67 | if (videoCaption.action === 'CREATE') { | ||
68 | obs = obs.pipe(switchMap(() => this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile))) | ||
69 | } else if (videoCaption.action === 'REMOVE') { | ||
70 | obs = obs.pipe(switchMap(() => this.removeCaption(videoId, videoCaption.language.id))) | ||
71 | } | ||
72 | } | ||
73 | |||
74 | return obs | ||
75 | } | ||
76 | } | ||