@@ -33,7 +33,7 @@ const DELETE_CHAR = '⌫';
33
33
34
34
/** Response from Google for automated transcript. */
35
35
interface GoogleTsResponse {
36
- status : 'requested' | 'in_progress' | 'complete' ;
36
+ status : 'requested' | 'in_progress' | 'complete' | 'error' ;
37
37
/** Full transcript text. */
38
38
value : string ;
39
39
/** Transcript text split into chunks - scored by transcription quality. */
@@ -42,11 +42,12 @@ interface GoogleTsResponse {
42
42
confidence : number ;
43
43
} > ;
44
44
languageCode : string ;
45
+ regionCode : string | null ;
45
46
}
46
47
47
48
/** Response from Google for automated translation. */
48
49
interface GoogleTxResponse {
49
- status : 'complete' ;
50
+ status : 'requested' | 'in_progress' | ' complete' | 'error ';
50
51
value : string ;
51
52
languageCode : string ;
52
53
}
@@ -484,15 +485,15 @@ processingActions.requestAutoTranscription.listen(
484
485
data : JSON . stringify ( data ) ,
485
486
} )
486
487
. done ( ( response : ProcessingDataResponse ) => {
487
- if (
488
- [ 'requested' , 'in_progress' ] . includes (
489
- response [ qpath ] ?. googlets ?. status ?? ''
490
- )
491
- ) {
488
+ const responseStatus = response [ qpath ] ?. googlets ?. status ;
489
+
490
+ if ( responseStatus === 'requested' || responseStatus === 'in_progress' ) {
492
491
processingActions . requestAutoTranscription . in_progress ( {
493
492
response,
494
493
submissionEditId,
495
494
} ) ;
495
+ } else if ( responseStatus === 'error' ) {
496
+ processingActions . requestAutoTranscription . failed ( 'unknown error' ) ;
496
497
} else {
497
498
processingActions . requestAutoTranscription . completed ( {
498
499
response,
@@ -711,7 +712,8 @@ processingActions.deleteTranslation.failed.listen(() => {
711
712
* `requestAutoTranslation` action
712
713
*
713
714
* For requestiong automatic translation from Back end. Translations are not as
714
- * time consuming as transcripts, so we don't use `in_progress` callback here.
715
+ * time consuming as transcripts, but we also use `in_progress` callback here,
716
+ * as it's needed for text longer than ~30k characters.
715
717
*/
716
718
interface RequestAutoTranslationFn {
717
719
(
@@ -749,9 +751,6 @@ processingActions.requestAutoTranslation.listen(
749
751
} ,
750
752
} ;
751
753
752
- // FIXME: large translations can also be asynchronous, and the back end
753
- // may return `in_progress`. We need the same kind of logic here as we
754
- // have in `requestAutoTranscription`
755
754
$ . ajax ( {
756
755
dataType : 'json' ,
757
756
contentType : 'application/json' ,
@@ -760,13 +759,17 @@ processingActions.requestAutoTranslation.listen(
760
759
data : JSON . stringify ( data ) ,
761
760
} )
762
761
. done ( ( response : ProcessingDataResponse ) => {
763
- if ( response [ qpath ] ?. googlets ?. status === 'complete' ) {
764
- processingActions . requestAutoTranslation . completed ( {
762
+ const responseStatus = response [ qpath ] ?. googletx ?. status ;
763
+
764
+ if ( responseStatus === 'requested' || responseStatus === 'in_progress' ) {
765
+ processingActions . requestAutoTranslation . in_progress ( {
765
766
response,
766
767
submissionEditId,
767
768
} ) ;
769
+ } else if ( responseStatus === 'error' ) {
770
+ processingActions . requestAutoTranslation . failed ( 'unknown error' ) ;
768
771
} else {
769
- processingActions . requestAutoTranslation . in_progress ( {
772
+ processingActions . requestAutoTranslation . completed ( {
770
773
response,
771
774
submissionEditId,
772
775
} ) ;
0 commit comments