Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Restrict failed-upload recovery (IndexedDB persist + Downloads fallback) to in-app recordings so filesystem uploads aren't duplicated, and hand audio back as a download once auto-retries are exhausted

Murtaza Nasirc267e8a05834
diff --git a/static/js/modules/composables/upload.js b/static/js/modules/composables/upload.js
index a2adc6cd..316c2c23 100644
--- a/static/js/modules/composables/upload.js
+++ b/static/js/modules/composables/upload.js
@@ -729,16 +729,23 @@ export function useUpload(state, utils) {
// If this failure is itself a resurfaced retry, just bump the retry
// count on the EXISTING IndexedDB record — don't store a duplicate or
// re-download. resurfaceFailedUploads() will pick it up again on the
- // next online/load (until it hits the retry cap).
+ // next online/load. Once the retry cap is reached, hand the audio
+ // back as a browser download instead of leaving the record trapped
+ // in IndexedDB (capped records are never resurfaced again).
if (fileItem._failedUploadId) {
+ const newRetryCount = (fileItem._retryCount || 0) + 1;
try {
await FailedUploads.updateRetryCount(
- fileItem._failedUploadId, (fileItem._retryCount || 0) + 1, error.message);
+ fileItem._failedUploadId, newRetryCount, error.message);
} catch (e) {
console.warn('[Upload] Could not bump retry count:', e);
}
- } else {
- // Defense-in-depth recovery (issue #297, #287, #313):
+ if (newRetryCount >= MAX_AUTO_RETRIES) {
+ await handOffExhaustedUpload(fileItem._failedUploadId, fileItem.file);
+ }
+ } else if (fileItem.fromInProgressRecording) {
+ // Defense-in-depth recovery (issue #297, #287, #313) for in-app
+ // recordings, whose ONLY copy lives in browser memory:
// 1. Persist the file to IndexedDB so it can be auto-retried
// in-app on the next online/page-load (resurfaceFailedUploads).
// 2. If IndexedDB persistence fails (quota exceeded, private
@@ -796,6 +803,13 @@ export function useUpload(state, utils) {
}
}
}
+ // else: the file came from the user's filesystem (picker or
+ // drag-drop), so the original still exists on disk and nothing is
+ // lost by the failure. Persisting a copy to IndexedDB — or worse,
+ // re-downloading a multi-GB file into Downloads — would only
+ // duplicate it. The queue item stays 'failed' with the error
+ // surfaced above; the user can re-add the file once the cause
+ // (e.g. a proxy size limit) is addressed.
} finally {
fileItem._xhr = null;
releaseUploadSlot();
@@ -1088,6 +1102,29 @@ export function useUpload(state, utils) {
const MAX_AUTO_RETRIES = 3;
let _isResurfacing = false;
+ // When auto-retry gives up on a persisted recording, hand the audio back
+ // to the user as a browser download and drop the IndexedDB record —
+ // otherwise capped records sit invisibly in IndexedDB forever (the
+ // resurfacing loop skips them) and the recording is effectively lost.
+ // Keeps the record when the download could not be triggered so a later
+ // pass can try again.
+ const handOffExhaustedUpload = async (failedUploadId, file) => {
+ const downloaded = FailedUploads.triggerLocalDownload(
+ file, file?.name || `speakr-recording-${Date.now()}.webm`);
+ if (!downloaded) return false;
+ try {
+ await FailedUploads.deleteFailedUpload(failedUploadId);
+ } catch (e) {
+ console.warn('[Upload] Could not delete exhausted upload record:', e);
+ }
+ showToast?.(
+ (t && t('toasts.uploadRetriesExhaustedDownloaded'))
+ || 'Automatic upload retries exhausted. The audio was saved to your Downloads folder.',
+ 'fa-file-download'
+ );
+ return true;
+ };
+
// Auto-retry path for #313: read the failed uploads persisted in IndexedDB,
// rebuild a File for each, and resubmit them through the normal upload queue
// (correct CSRF, visible in the Processing Queue, works in every browser —
@@ -1103,7 +1140,16 @@ export function useUpload(state, utils) {
let queued = 0;
for (const rec of failed) {
if (!rec || !rec.fileData) continue;
- if ((rec.retryCount || 0) >= MAX_AUTO_RETRIES) continue;
+ if ((rec.retryCount || 0) >= MAX_AUTO_RETRIES) {
+ // Records that hit the cap before this hand-off existed (or
+ // whose earlier hand-off download failed): give the audio
+ // back now instead of skipping it forever.
+ const file = new File([rec.fileData],
+ rec.fileName || `speakr-recording-${Date.now()}.webm`,
+ { type: rec.mimeType || 'audio/webm' });
+ await handOffExhaustedUpload(rec.id, file);
+ continue;
+ }
// Skip if this upload is already represented in the queue and
// actively in flight; otherwise drop a stale failed item so we
diff --git a/static/locales/de.json b/static/locales/de.json
index fd9017b3..bd7c561a 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -1781,6 +1781,7 @@
"uploadFailedDownloadedLocally": "Upload fehlgeschlagen. Audio wurde im Downloads-Ordner für einen späteren Versuch gespeichert.",
"uploadFailedNoRecovery": "Upload fehlgeschlagen und Audio konnte nicht lokal gespeichert werden. Bitte erneut aufnehmen.",
"uploadFailedWillRetry": "Upload fehlgeschlagen – gespeichert und wird bei erneuter Verbindung automatisch wiederholt.",
+ "uploadRetriesExhaustedDownloaded": "Automatische Upload-Wiederholungen erschöpft. Die Audiodatei wurde in Ihrem Downloads-Ordner gespeichert.",
"videoRecordingUnsupported": "Dieser Browser kann kein Video aufnehmen — es wird nur Audio aufgezeichnet."
},
"webhooks": {
diff --git a/static/locales/en.json b/static/locales/en.json
index 542b0e11..051daa12 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -1781,6 +1781,7 @@
"uploadFailedDownloadedLocally": "Upload failed. Audio saved to your Downloads folder for later retry.",
"uploadFailedNoRecovery": "Upload failed and audio could not be saved locally. Please record again.",
"uploadFailedWillRetry": "Upload failed — saved and will retry automatically when you reconnect.",
+ "uploadRetriesExhaustedDownloaded": "Automatic upload retries exhausted. The audio was saved to your Downloads folder.",
"videoRecordingUnsupported": "This browser cannot record video — capturing audio only."
},
"webhooks": {
diff --git a/static/locales/es.json b/static/locales/es.json
index 3fef390a..12f1bdcc 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -1781,6 +1781,7 @@
"uploadFailedDownloadedLocally": "Subida fallida. El audio se guardó en la carpeta de Descargas para reintentarlo más tarde.",
"uploadFailedNoRecovery": "Subida fallida y el audio no pudo guardarse localmente. Por favor, vuelva a grabar.",
"uploadFailedWillRetry": "Error en la subida — guardada y se reintentará automáticamente al reconectar.",
+ "uploadRetriesExhaustedDownloaded": "Se agotaron los reintentos automáticos de subida. El audio se guardó en tu carpeta de descargas.",
"videoRecordingUnsupported": "Este navegador no puede grabar vídeo; se capturará solo el audio."
},
"webhooks": {
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 02ef4174..4e43b496 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -1781,6 +1781,7 @@
"uploadFailedDownloadedLocally": "Échec de l'envoi. L'audio a été enregistré dans votre dossier Téléchargements pour une nouvelle tentative.",
"uploadFailedNoRecovery": "Échec de l'envoi et l'audio n'a pas pu être enregistré localement. Veuillez réenregistrer.",
"uploadFailedWillRetry": "Échec de l'envoi — enregistré et réessayé automatiquement à la reconnexion.",
+ "uploadRetriesExhaustedDownloaded": "Les tentatives automatiques d'envoi sont épuisées. L'audio a été enregistré dans votre dossier Téléchargements.",
"videoRecordingUnsupported": "Ce navigateur ne peut pas enregistrer la vidéo — capture de l'audio uniquement."
},
"webhooks": {
diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.json
index 41f5f70a..19c884ec 100644
--- a/static/locales/pt-BR.json
+++ b/static/locales/pt-BR.json
@@ -1781,6 +1781,7 @@
"uploadFailedDownloadedLocally": "Upload falhou. Áudio salvo na pasta Downloads para tentar novamente mais tarde.",
"uploadFailedNoRecovery": "Upload falhou e o áudio não pôde ser salvo localmente. Por favor, grave novamente.",
"uploadFailedWillRetry": "Falha no envio — salvo e será reenviado automaticamente quando você reconectar.",
+ "uploadRetriesExhaustedDownloaded": "As tentativas automáticas de envio se esgotaram. O áudio foi salvo na sua pasta de Downloads.",
"videoRecordingUnsupported": "Este navegador não consegue gravar vídeo — capturando apenas o áudio."
},
"webhooks": {
diff --git a/static/locales/ru.json b/static/locales/ru.json
index b64d7fd9..c1ca661b 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -1781,6 +1781,7 @@
"uploadFailedDownloadedLocally": "Загрузка не удалась. Аудио сохранено в папку «Загрузки» для повторной попытки.",
"uploadFailedNoRecovery": "Загрузка не удалась и аудио не удалось сохранить локально. Пожалуйста, запишите снова.",
"uploadFailedWillRetry": "Ошибка загрузки — сохранено и будет автоматически повторено при восстановлении связи.",
+ "uploadRetriesExhaustedDownloaded": "Автоматические повторные попытки загрузки исчерпаны. Аудио сохранено в папке «Загрузки».",
"videoRecordingUnsupported": "Этот браузер не может записывать видео — записывается только звук."
},
"webhooks": {
diff --git a/static/locales/zh.json b/static/locales/zh.json
index d9120e50..2c32629d 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -1781,6 +1781,7 @@
"uploadFailedDownloadedLocally": "上传失败。音频已保存到下载文件夹,可稍后重试。",
"uploadFailedNoRecovery": "上传失败,且音频未能本地保存。请重新录制。",
"uploadFailedWillRetry": "上传失败——已保存,将在重新联网后自动重试。",
+ "uploadRetriesExhaustedDownloaded": "自动重试上传已达上限。音频已保存到您的下载文件夹。",
"videoRecordingUnsupported": "此浏览器无法录制视频,将仅录制音频。"
},
"webhooks": {