import { VideoService } from '@app/shared/shared-main/video'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import { ResultList, VideoCaption } from '@shared/models'
+import { environment } from '../../../../environments/environment'
import { VideoCaptionEdit } from './video-caption-edit.model'
@Injectable()
removeCaption (videoId: number | string, language: string) {
return this.authHttp.delete(`${VideoService.BASE_VIDEO_URL}/${videoId}/captions/${language}`)
- .pipe(
- map(this.restExtractor.extractDataBool),
- catchError(res => this.restExtractor.handleError(res))
- )
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
}
addCaption (videoId: number | string, language: string, captionfile: File) {
const data = objectToFormData(body)
return this.authHttp.put(`${VideoService.BASE_VIDEO_URL}/${videoId}/captions/${language}`, data)
- .pipe(
- map(this.restExtractor.extractDataBool),
- catchError(res => this.restExtractor.handleError(res))
- )
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
}
updateCaptions (videoId: number | string, videoCaptions: VideoCaptionEdit[]) {
- let obs = of(true)
+ let obs: Observable<any> = of(undefined)
for (const videoCaption of videoCaptions) {
- if (videoCaption.action === 'CREATE') {
+ if (videoCaption.action === 'CREATE' || videoCaption.action === 'UPDATE') {
obs = obs.pipe(switchMap(() => this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile)))
} else if (videoCaption.action === 'REMOVE') {
obs = obs.pipe(switchMap(() => this.removeCaption(videoId, videoCaption.language.id)))
return obs
}
+
+ getCaptionContent ({ captionPath }: Pick<VideoCaption, 'captionPath'>) {
+ return this.authHttp.get(environment.originServerUrl + captionPath, { responseType: 'text' })
+ }
}