Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor(notes): unify the upload note save path (#1625)

Gabriel Steinfdcbceca48bb
diff --git a/src/components/notes/UploadAudioView.tsx b/src/components/notes/UploadAudioView.tsx
index 212c88eb9..67dd11d83 100644
--- a/src/components/notes/UploadAudioView.tsx
+++ b/src/components/notes/UploadAudioView.tsx
@@ -64,7 +64,7 @@ import { isTranscriptionContextAllowed } from "../../stores/policyRules";
import { usePolicyStore } from "../../stores/policyStore";
import { usePolicySnapshot, useTranscriptionContextAllowed } from "../../hooks/usePolicy";
import { resolveTranscriptionRoute } from "../../helpers/transcriptionRoute";
-import { buildUploadNoteMetadata } from "../../helpers/uploadNoteMetadata";
+import { saveUploadNote, uploadTitleFallback } from "../../services/uploadNotes";
type UploadState = "idle" | "selected" | "downloading" | "transcribing" | "complete" | "error";
@@ -691,33 +691,19 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: Uploa
if (currentFile.fromUrl) {
title = currentFile.name;
} else {
- const textFallback = res.text.trim().split(/\s+/).slice(0, 6).join(" ");
- const fallbackTitle =
- textFallback.length > 0
- ? textFallback + (res.text.trim().split(/\s+/).length > 6 ? "..." : "")
- : currentFile.name.replace(/\.[^.]+$/, "");
const aiTitle = await generateTitle(res.text);
if (runId !== runIdRef.current) return;
- title = aiTitle || fallbackTitle;
+ title = aiTitle || uploadTitleFallback(res.text, currentFile.name);
}
- const folderId = selectedFolderId ? Number(selectedFolderId) : null;
- const { audioDurationSeconds, noteUpdates } = buildUploadNoteMetadata(
- diarization,
- res.durationSeconds
- );
- const noteRes = await window.electronAPI.saveNote(
+ const noteRes = await saveUploadNote({
title,
- res.text,
- "upload",
- currentFile.name,
- audioDurationSeconds,
- folderId
- );
- if (noteRes.success && noteRes.note && noteUpdates) {
- // Best-effort: a failed metadata write must not error a saved note.
- await window.electronAPI.updateNote(noteRes.note.id, noteUpdates).catch(() => {});
- }
+ text: res.text,
+ sourceName: currentFile.name,
+ folderId: selectedFolderId ? Number(selectedFolderId) : null,
+ diarization,
+ durationSeconds: res.durationSeconds,
+ });
if (runId !== runIdRef.current) return;
if (noteRes.success && noteRes.note) setNoteId(noteRes.note.id);
if (currentTempPath) {
diff --git a/src/helpers/uploadNoteMetadata.js b/src/helpers/uploadNoteMetadata.js
deleted file mode 100644
index 2c5445a5e..000000000
--- a/src/helpers/uploadNoteMetadata.js
+++ /dev/null
@@ -1,33 +0,0 @@
-import { MAX_SPEAKER_COUNT } from "../constants/speakerDetection.json";
-
-// Renderer twin of normalizeStoredSpeakerCount in ./speakerCount.js. That file
-// is CommonJS for the main process (database.js, ipcHandlers.js), and renderer
-// source cannot load CJS modules under Vite — test/helpers/uploadNoteMetadata
-// .test.js holds the two implementations to identical outputs.
-function normalizeSpeakerCount(value) {
- const count = Number(value);
- if (!Number.isInteger(count) || count < 1) return null;
- return Math.min(count, MAX_SPEAKER_COUNT);
-}
-
-// What the upload and URL-ingest flows persist onto the note row about the
-// diarizer invocation, matching the meeting path's write semantics: the columns
-// are written only when diarization ran. A null diarization_enabled means "user
-// never chose" and consumers fall back to the global speaker setting — writing
-// 0 would force diarization off when recording into the note later. The
-// expected_speaker_count is only ever a count the diarizer was actually invoked
-// with (numSpeakers lingers in localStorage while its input is hidden); auto
-// detection stays null so isExplicitSpeakerCount never mistakes it for an
-// explicit choice.
-export function buildUploadNoteMetadata(diarization, durationSeconds) {
- return {
- audioDurationSeconds:
- Number.isFinite(durationSeconds) && durationSeconds > 0 ? durationSeconds : null,
- noteUpdates: diarization?.enabled
- ? {
- diarization_enabled: 1,
- expected_speaker_count: normalizeSpeakerCount(diarization.numSpeakers),
- }
- : null,
- };
-}
diff --git a/src/services/uploadNotes.ts b/src/services/uploadNotes.ts
new file mode 100644
index 000000000..31a0b5e44
--- /dev/null
+++ b/src/services/uploadNotes.ts
@@ -0,0 +1,86 @@
+import { MAX_SPEAKER_COUNT } from "../constants/speakerDetection.json";
+import type { DiarizationSettings } from "./fileTranscription";
+
+// Renderer twin of normalizeStoredSpeakerCount in ../helpers/speakerCount.js.
+// That file is CommonJS for the main process (database.js, ipcHandlers.js), and
+// renderer source cannot load CJS modules under Vite — test/services/
+// uploadNotes.test.js holds the two implementations to identical outputs.
+function normalizeSpeakerCount(value: number | null | undefined): number | null {
+ const count = Number(value);
+ if (!Number.isInteger(count) || count < 1) return null;
+ return Math.min(count, MAX_SPEAKER_COUNT);
+}
+
+// What an upload persists onto the note row about the diarizer invocation,
+// matching the meeting path's write semantics: the columns are written only
+// when diarization ran. A null diarization_enabled means "user never chose" and
+// consumers fall back to the global speaker setting — writing 0 would force
+// diarization off when recording into the note later. The
+// expected_speaker_count is only ever a count the diarizer was actually invoked
+// with (numSpeakers lingers in localStorage while its input is hidden); auto
+// detection stays null so isExplicitSpeakerCount never mistakes it for an
+// explicit choice.
+export function buildUploadNoteMetadata(
+ diarization: DiarizationSettings,
+ durationSeconds?: number | null
+) {
+ return {
+ audioDurationSeconds:
+ typeof durationSeconds === "number" && Number.isFinite(durationSeconds) && durationSeconds > 0
+ ? durationSeconds
+ : null,
+ noteUpdates: diarization.enabled
+ ? {
+ diarization_enabled: 1,
+ expected_speaker_count: normalizeSpeakerCount(diarization.numSpeakers),
+ }
+ : null,
+ };
+}
+
+interface SaveUploadNoteParams {
+ title: string;
+ text: string;
+ sourceName: string;
+ folderId: number | null;
+ diarization: DiarizationSettings;
+ durationSeconds?: number | null;
+}
+
+// The one save path for upload and URL-ingest notes, shared by the single-file
+// flow and the batch queue: the duration goes in the insert (updateNote does
+// not whitelist audio_duration_seconds), and the diarization columns follow
+// through updateNote — the same route the meeting path writes them through.
+export async function saveUploadNote({
+ title,
+ text,
+ sourceName,
+ folderId,
+ diarization,
+ durationSeconds,
+}: SaveUploadNoteParams) {
+ const { audioDurationSeconds, noteUpdates } = buildUploadNoteMetadata(
+ diarization,
+ durationSeconds
+ );
+ const res = await window.electronAPI.saveNote(
+ title,
+ text,
+ "upload",
+ sourceName,
+ audioDurationSeconds,
+ folderId
+ );
+ if (res.success && res.note && noteUpdates) {
+ // Best-effort: a failed metadata write must not error a saved note.
+ await window.electronAPI.updateNote(res.note.id, noteUpdates).catch(() => {});
+ }
+ return res;
+}
+
+// First words of the transcript, else the file name without its extension.
+export function uploadTitleFallback(text: string, fileName: string): string {
+ const words = text.trim().split(/\s+/);
+ const preview = words.slice(0, 6).join(" ") + (words.length > 6 ? "..." : "");
+ return preview || fileName.replace(/\.[^.]+$/, "");
+}
diff --git a/src/stores/batchQueueStore.ts b/src/stores/batchQueueStore.ts
index abf81b9c1..dac4b3da9 100644
--- a/src/stores/batchQueueStore.ts
+++ b/src/stores/batchQueueStore.ts
@@ -2,7 +2,7 @@ import { create } from "zustand";
import { transcribeFileWithSpeakers } from "../services/fileTranscription";
import type { FileTranscriptionConfig, DiarizationSettings } from "../services/fileTranscription";
import { DOWNLOAD_ERROR_KEYS, transcriptionErrorKey } from "../components/notes/shared";
-import { buildUploadNoteMetadata } from "../helpers/uploadNoteMetadata";
+import { saveUploadNote, uploadTitleFallback } from "../services/uploadNotes";
import { getSettings } from "./settingsStore";
import { isTranscriptionContextAllowed } from "./policyRules";
import { usePolicyStore } from "./policyStore";
@@ -222,32 +222,22 @@ export function processBatchQueue(
// titles as the single-file flow.
let noteTitle = noteName;
if (item.source === "file") {
- const words = finalText.trim().split(/\s+/);
- const fallback =
- words.slice(0, 6).join(" ") + (words.length > 6 ? "..." : "") ||
- noteName.replace(/\.[^.]+$/, "");
- noteTitle = (await transcribeOpts.generateTitle?.(finalText)) || fallback;
+ noteTitle =
+ (await transcribeOpts.generateTitle?.(finalText)) ||
+ uploadTitleFallback(finalText, noteName);
if (run !== runId) return;
}
- const { audioDurationSeconds, noteUpdates } = buildUploadNoteMetadata(
+ const noteRes = await saveUploadNote({
+ title: noteTitle,
+ text: finalText,
+ sourceName: noteName,
+ folderId: transcribeOpts.folderId,
diarization,
- transcriptionResult.durationSeconds
- );
- const noteRes = await window.electronAPI.saveNote(
- noteTitle,
- finalText,
- "upload",
- noteName,
- audioDurationSeconds,
- transcribeOpts.folderId
- );
+ durationSeconds: transcriptionResult.durationSeconds,
+ });
if (noteRes.success && noteRes.note) {
- if (noteUpdates) {
- // Best-effort: a failed metadata write must not error a saved transcription.
- await window.electronAPI.updateNote(noteRes.note.id, noteUpdates).catch(() => {});
- }
updateItem(item.id, {
status: "done",
progress: 100,
diff --git a/test/helpers/uploadNoteMetadata.test.js b/test/services/uploadNotes.test.js
similarity index 86%
rename from test/helpers/uploadNoteMetadata.test.js
rename to test/services/uploadNotes.test.js
index cffc9e947..7251be5dd 100644
--- a/test/helpers/uploadNoteMetadata.test.js
+++ b/test/services/uploadNotes.test.js
@@ -1,7 +1,7 @@
const test = require("node:test");
const assert = require("node:assert/strict");
-const load = () => import("../../src/helpers/uploadNoteMetadata.js");
+const load = () => import("../../src/services/uploadNotes.ts");
const { MAX_SPEAKER_COUNT } = require("../../src/constants/speakerDetection.json");
test("maps the diarizer invocation onto the note columns", async () => {
@@ -75,7 +75,18 @@ test("unusable durations degrade to null", async () => {
}
});
-// uploadNoteMetadata.js carries a renderer twin of the main-process
+test("upload titles fall back to the transcript, then the file name", async () => {
+ const { uploadTitleFallback } = await load();
+
+ assert.equal(uploadTitleFallback("one two three", "board.m4a"), "one two three");
+ assert.equal(
+ uploadTitleFallback("one two three four five six seven", "board.m4a"),
+ "one two three four five six..."
+ );
+ assert.equal(uploadTitleFallback(" ", "board-meeting.m4a"), "board-meeting");
+});
+
+// uploadNotes.ts carries a renderer twin of the main-process
// normalizeStoredSpeakerCount (CJS, unloadable from renderer source). Hold the
// two implementations to identical outputs so they cannot drift apart.
test("speaker-count normalization matches the main-process implementation", async () => {