Skip to content

Commit 089f73c

Browse files
handle in_progress and error statuses for transcripts and translations consistently
1 parent 6728c42 commit 089f73c

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

jsapp/js/components/processing/processingActions.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const DELETE_CHAR = '⌫';
3333

3434
/** Response from Google for automated transcript. */
3535
interface GoogleTsResponse {
36-
status: 'requested' | 'in_progress' | 'complete';
36+
status: 'requested' | 'in_progress' | 'complete' | 'error';
3737
/** Full transcript text. */
3838
value: string;
3939
/** Transcript text split into chunks - scored by transcription quality. */
@@ -42,11 +42,12 @@ interface GoogleTsResponse {
4242
confidence: number;
4343
}>;
4444
languageCode: string;
45+
regionCode: string | null;
4546
}
4647

4748
/** Response from Google for automated translation. */
4849
interface GoogleTxResponse {
49-
status: 'complete';
50+
status: 'requested' | 'in_progress' | 'complete' | 'error';
5051
value: string;
5152
languageCode: string;
5253
}
@@ -484,15 +485,15 @@ processingActions.requestAutoTranscription.listen(
484485
data: JSON.stringify(data),
485486
})
486487
.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') {
492491
processingActions.requestAutoTranscription.in_progress({
493492
response,
494493
submissionEditId,
495494
});
495+
} else if (responseStatus === 'error') {
496+
processingActions.requestAutoTranscription.failed('unknown error');
496497
} else {
497498
processingActions.requestAutoTranscription.completed({
498499
response,
@@ -711,7 +712,8 @@ processingActions.deleteTranslation.failed.listen(() => {
711712
* `requestAutoTranslation` action
712713
*
713714
* 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.
715717
*/
716718
interface RequestAutoTranslationFn {
717719
(
@@ -749,9 +751,6 @@ processingActions.requestAutoTranslation.listen(
749751
},
750752
};
751753

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`
755754
$.ajax({
756755
dataType: 'json',
757756
contentType: 'application/json',
@@ -760,13 +759,17 @@ processingActions.requestAutoTranslation.listen(
760759
data: JSON.stringify(data),
761760
})
762761
.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({
765766
response,
766767
submissionEditId,
767768
});
769+
} else if (responseStatus === 'error') {
770+
processingActions.requestAutoTranslation.failed('unknown error');
768771
} else {
769-
processingActions.requestAutoTranslation.in_progress({
772+
processingActions.requestAutoTranslation.completed({
770773
response,
771774
submissionEditId,
772775
});

0 commit comments

Comments
 (0)