Skip to content

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

Python

Fix crash recovery: properly convert Vue reactive objects and expose formatDateTime

Murtaza Nasir2960d3cee8ed
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 349a29bc..2aca12d1 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -1848,6 +1848,7 @@ document.addEventListener('DOMContentLoaded', async () => {
formatTime,
formatDuration,
formatEventDateTime,
+ formatDateTime: formatEventDateTime, // Alias for recovery modal
setGlobalError,
showToast,
getContrastTextColor,
diff --git a/static/js/modules/composables/audio.js b/static/js/modules/composables/audio.js
index eaf65315..afe219df 100644
--- a/static/js/modules/composables/audio.js
+++ b/static/js/modules/composables/audio.js
@@ -359,16 +359,16 @@ export function useAudio(state, utils) {
const recorder = new MediaRecorder(stream, { mimeType });
- // Start IndexedDB recording session
+ // Start IndexedDB recording session - convert Vue reactive objects to plain objects
try {
await RecordingDB.startRecordingSession({
mode,
- notes: recordingNotes.value,
- tags: selectedTagIds.value,
+ notes: recordingNotes.value || '',
+ tags: selectedTagIds.value ? [...selectedTagIds.value] : [], // Convert reactive array to plain array
asrOptions: {
- language: asrLanguage.value,
- min_speakers: asrMinSpeakers.value,
- max_speakers: asrMaxSpeakers.value
+ language: asrLanguage.value || '',
+ min_speakers: asrMinSpeakers.value || '',
+ max_speakers: asrMaxSpeakers.value || ''
},
mimeType
});
@@ -385,11 +385,11 @@ export function useAudio(state, utils) {
await RecordingDB.saveChunk(event.data, currentChunkIndex);
await RecordingDB.updateRecordingMetadata({
duration: recordingTime.value,
- notes: recordingNotes.value
+ notes: recordingNotes.value || ''
});
currentChunkIndex++;
} catch (dbError) {
- console.warn('[Recording] Failed to save chunk to IndexedDB:', dbError);
+ // Don't spam console - recording continues in memory regardless
}
}
};
diff --git a/static/js/modules/db/recording-persistence.js b/static/js/modules/db/recording-persistence.js
index b7f8531d..067c358d 100644
--- a/static/js/modules/db/recording-persistence.js
+++ b/static/js/modules/db/recording-persistence.js
@@ -9,6 +9,16 @@ const STORE_NAME = 'activeRecording';
let dbInstance = null;
+/**
+ * Helper to promisify IDBRequest
+ */
+const promisifyRequest = (request) => {
+ return new Promise((resolve, reject) => {
+ request.onsuccess = () => resolve(request.result);
+ request.onerror = () => reject(request.error);
+ });
+};
+
/**
* Initialize IndexedDB
*/
@@ -67,7 +77,7 @@ export const startRecordingSession = async (recordingData) => {
duration: 0
};
- await objectStore.put(session);
+ await promisifyRequest(objectStore.put(session));
console.log('[RecordingDB] Recording session started:', session.id);
return session;
} catch (error) {
@@ -81,21 +91,22 @@ export const startRecordingSession = async (recordingData) => {
*/
export const saveChunk = async (chunkBlob, chunkIndex) => {
try {
+ // Do async prep work BEFORE creating transaction to avoid auto-close
const db = await initDB();
+ const arrayBuffer = await chunkBlob.arrayBuffer();
+
+ // Now create transaction and do all DB operations quickly
const transaction = db.transaction([STORE_NAME], 'readwrite');
const objectStore = transaction.objectStore(STORE_NAME);
// Get current session
- const session = await objectStore.get('current');
+ const session = await promisifyRequest(objectStore.get('current'));
if (!session) {
console.warn('[RecordingDB] No active session found');
return;
}
- // Convert Blob to ArrayBuffer for storage
- const arrayBuffer = await chunkBlob.arrayBuffer();
-
// Add chunk to session
session.chunks.push({
index: chunkIndex,
@@ -104,8 +115,8 @@ export const saveChunk = async (chunkBlob, chunkIndex) => {
timestamp: Date.now()
});
- // Update session
- await objectStore.put(session);
+ // Update session - must happen before transaction auto-closes
+ await promisifyRequest(objectStore.put(session));
console.log(`[RecordingDB] Chunk ${chunkIndex} saved (${chunkBlob.size} bytes)`);
} catch (error) {
console.error('[RecordingDB] Failed to save chunk:', error);
@@ -122,7 +133,7 @@ export const updateRecordingMetadata = async (updates) => {
const transaction = db.transaction([STORE_NAME], 'readwrite');
const objectStore = transaction.objectStore(STORE_NAME);
- const session = await objectStore.get('current');
+ const session = await promisifyRequest(objectStore.get('current'));
if (!session) {
console.warn('[RecordingDB] No active session to update');
@@ -131,7 +142,7 @@ export const updateRecordingMetadata = async (updates) => {
// Merge updates
Object.assign(session, updates);
- await objectStore.put(session);
+ await promisifyRequest(objectStore.put(session));
console.log('[RecordingDB] Metadata updated:', updates);
} catch (error) {
@@ -148,7 +159,7 @@ export const checkForRecoverableRecording = async () => {
const transaction = db.transaction([STORE_NAME], 'readonly');
const objectStore = transaction.objectStore(STORE_NAME);
- const session = await objectStore.get('current');
+ const session = await promisifyRequest(objectStore.get('current'));
if (!session || !session.chunks || session.chunks.length === 0) {
return null;
@@ -187,7 +198,7 @@ export const recoverRecording = async () => {
const transaction = db.transaction([STORE_NAME], 'readonly');
const objectStore = transaction.objectStore(STORE_NAME);
- const session = await objectStore.get('current');
+ const session = await promisifyRequest(objectStore.get('current'));
if (!session || !session.chunks || session.chunks.length === 0) {
console.warn('[RecordingDB] No recording to recover');
@@ -228,7 +239,7 @@ export const clearRecordingSession = async () => {
const transaction = db.transaction([STORE_NAME], 'readwrite');
const objectStore = transaction.objectStore(STORE_NAME);
- await objectStore.delete('current');
+ await promisifyRequest(objectStore.delete('current'));
console.log('[RecordingDB] Recording session cleared');
} catch (error) {
console.error('[RecordingDB] Failed to clear session:', error);