diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-01 08:51:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-01 08:54:58 +0200 |
commit | ed4c3c091009f85dd5e2775087b33ebd7f22ffd2 (patch) | |
tree | 1d182d04f3e48f1aff7d647a7b026f1d77d21fe6 /client/src/app/shared/video-caption | |
parent | 6360e12616d54c2321ee5e3a6523a8b60d70c0a7 (diff) | |
download | PeerTube-ed4c3c091009f85dd5e2775087b33ebd7f22ffd2.tar.gz PeerTube-ed4c3c091009f85dd5e2775087b33ebd7f22ffd2.tar.zst PeerTube-ed4c3c091009f85dd5e2775087b33ebd7f22ffd2.zip |
Update captions in sequence to avoid concurrence issues
Diffstat (limited to 'client/src/app/shared/video-caption')
-rw-r--r-- | client/src/app/shared/video-caption/video-caption.service.ts | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/client/src/app/shared/video-caption/video-caption.service.ts b/client/src/app/shared/video-caption/video-caption.service.ts index a1838ab16..977f6253a 100644 --- a/client/src/app/shared/video-caption/video-caption.service.ts +++ b/client/src/app/shared/video-caption/video-caption.service.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { catchError, map, switchMap } from 'rxjs/operators' | 1 | import { catchError, map, switchMap } from 'rxjs/operators' |
2 | import { HttpClient } from '@angular/common/http' | 2 | import { HttpClient } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { forkJoin, Observable, of } from 'rxjs' | 4 | import { Observable, of } from 'rxjs' |
5 | import { peertubeTranslate, ResultList } from '../../../../../shared' | 5 | import { peertubeTranslate, ResultList } from '../../../../../shared' |
6 | import { RestExtractor } from '../rest' | 6 | import { RestExtractor } from '../rest' |
7 | import { VideoService } from '@app/shared/video/video.service' | 7 | import { VideoService } from '@app/shared/video/video.service' |
@@ -61,22 +61,16 @@ export class VideoCaptionService { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | updateCaptions (videoId: number | string, videoCaptions: VideoCaptionEdit[]) { | 63 | updateCaptions (videoId: number | string, videoCaptions: VideoCaptionEdit[]) { |
64 | const observables: Observable<any>[] = [] | 64 | let obs = of(true) |
65 | 65 | ||
66 | for (const videoCaption of videoCaptions) { | 66 | for (const videoCaption of videoCaptions) { |
67 | if (videoCaption.action === 'CREATE') { | 67 | if (videoCaption.action === 'CREATE') { |
68 | observables.push( | 68 | obs = obs.pipe(switchMap(() => this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile))) |
69 | this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile) | ||
70 | ) | ||
71 | } else if (videoCaption.action === 'REMOVE') { | 69 | } else if (videoCaption.action === 'REMOVE') { |
72 | observables.push( | 70 | obs = obs.pipe(switchMap(() => this.removeCaption(videoId, videoCaption.language.id))) |
73 | this.removeCaption(videoId, videoCaption.language.id) | ||
74 | ) | ||
75 | } | 71 | } |
76 | } | 72 | } |
77 | 73 | ||
78 | if (observables.length === 0) return of(undefined) | 74 | return obs |
79 | |||
80 | return forkJoin(observables) | ||
81 | } | 75 | } |
82 | } | 76 | } |