mirror of https://github.com/Chocobozzz/PeerTube
Correctly handle transcription conflicts
parent
3c9d1ff5e3
commit
3a71086e35
|
@ -419,8 +419,36 @@ export class VideoListComponent extends RestTable <Video> implements OnInit {
|
|||
private generateCaption (videos: Video[]) {
|
||||
this.videoCaptionService.generateCaption(videos.map(v => v.id))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.notifier.success($localize`Transcription jobs created.`)
|
||||
next: result => {
|
||||
const messages: string[] = []
|
||||
|
||||
if (result.success) {
|
||||
this.notifier.success(
|
||||
formatICU(
|
||||
$localize`{count, plural, =1 {1 transcription job created.} other {{count} transcription jobs created.}}`,
|
||||
{ count: result.success }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (result.alreadyHasCaptions) {
|
||||
this.notifier.info(
|
||||
formatICU(
|
||||
$localize`{count, plural, =1 {1 video already has captions.} other {{count} videos already have captions.}}`,
|
||||
{ count: result.alreadyHasCaptions }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (result.alreadyBeingTranscribed) {
|
||||
this.notifier.info(
|
||||
formatICU(
|
||||
// eslint-disable-next-line max-len
|
||||
$localize`{count, plural, =1 {1 video is already being transcribed.} other {{count} videos are already being transcribed.}}`,
|
||||
{ count: result.alreadyBeingTranscribed }
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
error: err => this.notifier.error(err.message)
|
||||
|
|
|
@ -3,8 +3,8 @@ import { Injectable } from '@angular/core'
|
|||
import { RestExtractor, ServerService } from '@app/core'
|
||||
import { objectToFormData } from '@app/helpers'
|
||||
import { peertubeTranslate, sortBy } from '@peertube/peertube-core-utils'
|
||||
import { ResultList, VideoCaption } from '@peertube/peertube-models'
|
||||
import { Observable, from, of } from 'rxjs'
|
||||
import { PeerTubeProblemDocument, ResultList, ServerErrorCode, VideoCaption } from '@peertube/peertube-models'
|
||||
import { Observable, from, of, throwError } from 'rxjs'
|
||||
import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators'
|
||||
import { environment } from '../../../../environments/environment'
|
||||
import { VideoPasswordService } from '../video/video-password.service'
|
||||
|
@ -78,8 +78,35 @@ export class VideoCaptionService {
|
|||
generateCaption (videoIds: (number | string)[]) {
|
||||
return from(videoIds)
|
||||
.pipe(
|
||||
concatMap(videoId => this.authHttp.post(`${VideoService.BASE_VIDEO_URL}/${videoId}/captions/generate`, {})),
|
||||
concatMap(videoId => {
|
||||
return this.authHttp.post(`${VideoService.BASE_VIDEO_URL}/${videoId}/captions/generate`, {})
|
||||
.pipe(
|
||||
map(() => 'success' as 'success'),
|
||||
catchError(err => {
|
||||
const error: PeerTubeProblemDocument = err.error
|
||||
|
||||
if (error?.code === ServerErrorCode.VIDEO_ALREADY_HAS_CAPTIONS) {
|
||||
return of('already-has-captions' as 'already-has-captions')
|
||||
}
|
||||
|
||||
if (error?.code === ServerErrorCode.VIDEO_ALREADY_BEING_TRANSCRIBED) {
|
||||
return of('already-being-transcribed' as 'already-being-transcribed')
|
||||
}
|
||||
|
||||
return throwError(() => err)
|
||||
})
|
||||
)
|
||||
}),
|
||||
toArray(),
|
||||
map(data => {
|
||||
return data.reduce((p, c) => {
|
||||
if (c === 'success') p.success += 1
|
||||
if (c === 'already-has-captions') p.alreadyHasCaptions += 1
|
||||
if (c === 'already-being-transcribed') p.alreadyBeingTranscribed += 1
|
||||
|
||||
return p
|
||||
}, { success: 0, alreadyHasCaptions: 0, alreadyBeingTranscribed: 0 })
|
||||
}),
|
||||
catchError(err => this.restExtractor.handleError(err))
|
||||
)
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ export const ServerErrorCode = {
|
|||
|
||||
VIDEO_ALREADY_BEING_TRANSCODED: 'video_already_being_transcoded',
|
||||
VIDEO_ALREADY_BEING_TRANSCRIBED: 'video_already_being_transcribed',
|
||||
VIDEO_ALREADY_HAS_CAPTIONS: 'video_already_has_captions',
|
||||
|
||||
MAX_USER_VIDEO_QUOTA_EXCEEDED_FOR_USER_EXPORT: 'max_user_video_quota_exceeded_for_user_export'
|
||||
} as const
|
||||
|
|
|
@ -83,6 +83,7 @@ export const generateVideoCaptionValidator = [
|
|||
if (captions.length !== 0) {
|
||||
return res.fail({
|
||||
status: HttpStatusCode.BAD_REQUEST_400,
|
||||
type: ServerErrorCode.VIDEO_ALREADY_HAS_CAPTIONS,
|
||||
message: 'This video already has captions'
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue