Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix: API keys i18n collision, expiration UI, dedupe constants
Gabriel Steinec86972ed18c
diff --git a/src/components/ApiKeysSection.tsx b/src/components/ApiKeysSection.tsxindex 4743aff44..7bacde15c 100644--- a/src/components/ApiKeysSection.tsx+++ b/src/components/ApiKeysSection.tsx@@ -15,14 +15,20 @@ import {DialogFooter,ConfirmDialog,} from "./ui/dialog";+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";import { SectionHeader, SettingsPanel, SettingsPanelRow } from "./ui/SettingsSection";import { ApiKeysService } from "../services/ApiKeysService";import type { ApiKey } from "../services/ApiKeysService";+import {+ API_SCOPES,+ API_SCOPE_I18N_KEY,+ API_KEY_EXPIRY_OPTIONS,+ MAX_API_KEYS,+ type ApiScope,+} from "../constants/apiKeys";-const MAX_KEYS = 5;const MAX_NAME_LENGTH = 100;--const ALL_SCOPES = ["notes:read", "notes:write", "transcriptions:read", "usage:read"] as const;+const DEFAULT_EXPIRY_VALUE = "never";function formatRelativeTime(dateString: string): string {const seconds = Math.floor((Date.now() - new Date(dateString).getTime()) / 1000);@@ -89,7 +95,7 @@ export default function ApiKeysSection() {title={t("apiKeysSection.title")}description={t("apiKeysSection.description")}/>- {!isLoading && keys.length > 0 && keys.length < MAX_KEYS && (+ {!isLoading && keys.length > 0 && keys.length < MAX_API_KEYS && (<Button variant="outline" size="sm" onClick={() => setCreateOpen(true)}><Plus className="h-3.5 w-3.5 mr-1.5" />{t("apiKeysSection.createButton")}@@ -141,7 +147,9 @@ export default function ApiKeysSection() {<div className="flex items-center gap-1.5 flex-wrap">{apiKey.scopes.map((scope) => (<Badge key={scope} variant="outline" className="text-[10px] px-1.5 py-0">- {t(`apiKeysSection.scopes.${scope}`)}+ {t(+ `apiKeysSection.scopes.${API_SCOPE_I18N_KEY[scope as ApiScope] ?? scope}`+ )}</Badge>))}<span className="text-[10px] text-muted-foreground/50 ml-1">@@ -165,10 +173,10 @@ export default function ApiKeysSection() {</SettingsPanelRow>))}- {keys.length >= MAX_KEYS && (+ {keys.length >= MAX_API_KEYS && (<SettingsPanelRow><p className="text-[10px] text-muted-foreground/50 text-center">- {t("apiKeysSection.maxKeysReached", { max: MAX_KEYS })}+ {t("apiKeysSection.maxKeysReached", { max: MAX_API_KEYS })}</p></SettingsPanelRow>)}@@ -211,14 +219,16 @@ function CreateKeyDialog({const { toast } = useToast();const [name, setName] = useState("");- const [scopes, setScopes] = useState<Set<string>>(() => new Set(ALL_SCOPES));+ const [scopes, setScopes] = useState<Set<ApiScope>>(() => new Set(API_SCOPES));+ const [expiry, setExpiry] = useState<string>(DEFAULT_EXPIRY_VALUE);const [isSubmitting, setIsSubmitting] = useState(false);const [rawKey, setRawKey] = useState<string | null>(null);const [copied, setCopied] = useState(false);const resetForm = () => {setName("");- setScopes(new Set(ALL_SCOPES));+ setScopes(new Set(API_SCOPES));+ setExpiry(DEFAULT_EXPIRY_VALUE);setIsSubmitting(false);setRawKey(null);setCopied(false);@@ -236,7 +246,12 @@ function CreateKeyDialog({if (!name.trim() || scopes.size === 0) return;setIsSubmitting(true);try {- const result = await ApiKeysService.create(name.trim(), Array.from(scopes));+ const expiresInDays = API_KEY_EXPIRY_OPTIONS.find((o) => o.value === expiry)?.days ?? null;+ const result = await ApiKeysService.create({+ name: name.trim(),+ scopes: Array.from(scopes),+ expiresInDays,+ });setRawKey(result.key);await onCreated();} catch {@@ -264,7 +279,7 @@ function CreateKeyDialog({}};- const toggleScope = (scope: string) => {+ const toggleScope = (scope: ApiScope) => {setScopes((prev) => {const next = new Set(prev);if (next.has(scope)) {@@ -356,7 +371,7 @@ function CreateKeyDialog({{t("apiKeysSection.create.scopesLabel")}</label><div className="space-y-1">- {ALL_SCOPES.map((scope) => (+ {API_SCOPES.map((scope) => (<labelkey={scope}className="flex items-center gap-2.5 rounded-md px-2.5 py-1.5 cursor-pointer hover:bg-muted/50 dark:hover:bg-surface-raised/30 transition-colors"@@ -368,12 +383,30 @@ function CreateKeyDialog({className="h-3.5 w-3.5 rounded border-border accent-primary cursor-pointer"/><span className="text-xs text-foreground">- {t(`apiKeysSection.scopes.${scope}`)}+ {t(`apiKeysSection.scopes.${API_SCOPE_I18N_KEY[scope]}`)}</span></label>))}</div></div>++ <div className="space-y-1.5">+ <label className="text-xs font-medium text-foreground">+ {t("apiKeysSection.create.expiryLabel")}+ </label>+ <Select value={expiry} onValueChange={setExpiry}>+ <SelectTrigger className="h-9 text-xs">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {API_KEY_EXPIRY_OPTIONS.map((option) => (+ <SelectItem key={option.value} value={option.value} className="text-xs">+ {t(`apiKeysSection.create.expiryOptions.${option.value}`)}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </div></div><DialogFooter>diff --git a/src/constants/apiKeys.ts b/src/constants/apiKeys.tsnew file mode 100644index 000000000..d4553d8ac--- /dev/null+++ b/src/constants/apiKeys.ts@@ -0,0 +1,35 @@+// Source of truth for the desktop side of the public API key UI.+// Keep API_SCOPES and MAX_API_KEYS in sync with openwhispr-api/lib/api-keys.ts.++export const API_SCOPES = [+ "notes:read",+ "notes:write",+ "transcriptions:read",+ "usage:read",+] as const;++export type ApiScope = (typeof API_SCOPES)[number];++export const MAX_API_KEYS = 5;++// i18next reserves ":" as the namespace separator, so scope ids can't be used+// as translation keys directly. This map gives each scope an i18n-safe alias.+export const API_SCOPE_I18N_KEY: Record<ApiScope, string> = {+ "notes:read": "notesRead",+ "notes:write": "notesWrite",+ "transcriptions:read": "transcriptionsRead",+ "usage:read": "usageRead",+};++export interface ApiKeyExpiryOption {+ value: string;+ days: number | null;+}++export const API_KEY_EXPIRY_OPTIONS: readonly ApiKeyExpiryOption[] = [+ { value: "never", days: null },+ { value: "30days", days: 30 },+ { value: "60days", days: 60 },+ { value: "90days", days: 90 },+ { value: "1year", days: 365 },+] as const;diff --git a/src/locales/de/translation.json b/src/locales/de/translation.jsonindex e374a6d1b..f99bacfc3 100644--- a/src/locales/de/translation.json+++ b/src/locales/de/translation.json@@ -2021,6 +2021,14 @@"nameLabel": "Schlüsselname","namePlaceholder": "z. B. Meine Integration","scopesLabel": "Berechtigungen",+ "expiryLabel": "Ablauf",+ "expiryOptions": {+ "never": "Läuft nicht ab",+ "30days": "30 Tage",+ "60days": "60 Tage",+ "90days": "90 Tage",+ "1year": "1 Jahr"+ },"submit": "Erstellen","cancel": "Abbrechen"},@@ -2032,10 +2040,10 @@"done": "Fertig"},"scopes": {- "notes:read": "Notizen lesen",- "notes:write": "Notizen erstellen und bearbeiten",- "transcriptions:read": "Transkriptionen lesen",- "usage:read": "Nutzung anzeigen"+ "notesRead": "Notizen lesen",+ "notesWrite": "Notizen erstellen und bearbeiten",+ "transcriptionsRead": "Transkriptionen lesen",+ "usageRead": "Nutzung anzeigen"},"revoke": {"button": "Widerrufen",diff --git a/src/locales/en/translation.json b/src/locales/en/translation.jsonindex e6154e070..e15074ff3 100644--- a/src/locales/en/translation.json+++ b/src/locales/en/translation.json@@ -657,6 +657,14 @@"nameLabel": "Key Name","namePlaceholder": "e.g. My Integration","scopesLabel": "Permissions",+ "expiryLabel": "Expiration",+ "expiryOptions": {+ "never": "Never expires",+ "30days": "30 days",+ "60days": "60 days",+ "90days": "90 days",+ "1year": "1 year"+ },"submit": "Create","cancel": "Cancel"},@@ -668,10 +676,10 @@"done": "Done"},"scopes": {- "notes:read": "Read notes",- "notes:write": "Create & edit notes",- "transcriptions:read": "Read transcriptions",- "usage:read": "View usage"+ "notesRead": "Read notes",+ "notesWrite": "Create & edit notes",+ "transcriptionsRead": "Read transcriptions",+ "usageRead": "View usage"},"revoke": {"button": "Revoke",diff --git a/src/locales/es/translation.json b/src/locales/es/translation.jsonindex 3ae0b2847..a17a414a8 100644--- a/src/locales/es/translation.json+++ b/src/locales/es/translation.json@@ -609,6 +609,14 @@"nameLabel": "Nombre de la clave","namePlaceholder": "ej. Mi Integración","scopesLabel": "Permisos",+ "expiryLabel": "Caducidad",+ "expiryOptions": {+ "never": "Nunca caduca",+ "30days": "30 días",+ "60days": "60 días",+ "90days": "90 días",+ "1year": "1 año"+ },"submit": "Crear","cancel": "Cancelar"},@@ -620,10 +628,10 @@"done": "Listo"},"scopes": {- "notes:read": "Leer notas",- "notes:write": "Crear y editar notas",- "transcriptions:read": "Leer transcripciones",- "usage:read": "Ver uso"+ "notesRead": "Leer notas",+ "notesWrite": "Crear y editar notas",+ "transcriptionsRead": "Leer transcripciones",+ "usageRead": "Ver uso"},"revoke": {"button": "Revocar",diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.jsonindex 52ea888a6..3ae246748 100644--- a/src/locales/fr/translation.json+++ b/src/locales/fr/translation.json@@ -609,6 +609,14 @@"nameLabel": "Nom de la clé","namePlaceholder": "ex. Mon intégration","scopesLabel": "Autorisations",+ "expiryLabel": "Expiration",+ "expiryOptions": {+ "never": "N'expire jamais",+ "30days": "30 jours",+ "60days": "60 jours",+ "90days": "90 jours",+ "1year": "1 an"+ },"submit": "Créer","cancel": "Annuler"},@@ -620,10 +628,10 @@"done": "Terminé"},"scopes": {- "notes:read": "Lire les notes",- "notes:write": "Créer et modifier les notes",- "transcriptions:read": "Lire les transcriptions",- "usage:read": "Voir l'utilisation"+ "notesRead": "Lire les notes",+ "notesWrite": "Créer et modifier les notes",+ "transcriptionsRead": "Lire les transcriptions",+ "usageRead": "Voir l'utilisation"},"revoke": {"button": "Révoquer",diff --git a/src/locales/it/translation.json b/src/locales/it/translation.jsonindex 2bdc03a28..9dd961ba3 100644--- a/src/locales/it/translation.json+++ b/src/locales/it/translation.json@@ -2021,6 +2021,14 @@"nameLabel": "Nome della chiave","namePlaceholder": "es. La mia integrazione","scopesLabel": "Permessi",+ "expiryLabel": "Scadenza",+ "expiryOptions": {+ "never": "Non scade mai",+ "30days": "30 giorni",+ "60days": "60 giorni",+ "90days": "90 giorni",+ "1year": "1 anno"+ },"submit": "Crea","cancel": "Annulla"},@@ -2032,10 +2040,10 @@"done": "Fatto"},"scopes": {- "notes:read": "Leggi note",- "notes:write": "Crea e modifica note",- "transcriptions:read": "Leggi trascrizioni",- "usage:read": "Visualizza utilizzo"+ "notesRead": "Leggi note",+ "notesWrite": "Crea e modifica note",+ "transcriptionsRead": "Leggi trascrizioni",+ "usageRead": "Visualizza utilizzo"},"revoke": {"button": "Revoca",diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.jsonindex afabb5dab..a4ded1d98 100644--- a/src/locales/ja/translation.json+++ b/src/locales/ja/translation.json@@ -2021,6 +2021,14 @@"nameLabel": "キー名","namePlaceholder": "例: マイインテグレーション","scopesLabel": "権限",+ "expiryLabel": "有効期限",+ "expiryOptions": {+ "never": "無期限",+ "30days": "30日間",+ "60days": "60日間",+ "90days": "90日間",+ "1year": "1年"+ },"submit": "作成","cancel": "キャンセル"},@@ -2032,10 +2040,10 @@"done": "完了"},"scopes": {- "notes:read": "ノートの読み取り",- "notes:write": "ノートの作成と編集",- "transcriptions:read": "文字起こしの読み取り",- "usage:read": "使用状況の表示"+ "notesRead": "ノートの読み取り",+ "notesWrite": "ノートの作成と編集",+ "transcriptionsRead": "文字起こしの読み取り",+ "usageRead": "使用状況の表示"},"revoke": {"button": "取り消し",diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.jsonindex 740b8881d..d5d166e87 100644--- a/src/locales/pt/translation.json+++ b/src/locales/pt/translation.json@@ -2021,6 +2021,14 @@"nameLabel": "Nome da chave","namePlaceholder": "ex. Minha Integração","scopesLabel": "Permissões",+ "expiryLabel": "Expiração",+ "expiryOptions": {+ "never": "Nunca expira",+ "30days": "30 dias",+ "60days": "60 dias",+ "90days": "90 dias",+ "1year": "1 ano"+ },"submit": "Criar","cancel": "Cancelar"},@@ -2032,10 +2040,10 @@"done": "Concluído"},"scopes": {- "notes:read": "Ler notas",- "notes:write": "Criar e editar notas",- "transcriptions:read": "Ler transcrições",- "usage:read": "Ver uso"+ "notesRead": "Ler notas",+ "notesWrite": "Criar e editar notas",+ "transcriptionsRead": "Ler transcrições",+ "usageRead": "Ver uso"},"revoke": {"button": "Revogar",diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.jsonindex 43e311d9a..560a61aa4 100644--- a/src/locales/ru/translation.json+++ b/src/locales/ru/translation.json@@ -2021,6 +2021,14 @@"nameLabel": "Название ключа","namePlaceholder": "напр. Моя интеграция","scopesLabel": "Разрешения",+ "expiryLabel": "Срок действия",+ "expiryOptions": {+ "never": "Бессрочно",+ "30days": "30 дней",+ "60days": "60 дней",+ "90days": "90 дней",+ "1year": "1 год"+ },"submit": "Создать","cancel": "Отмена"},@@ -2032,10 +2040,10 @@"done": "Готово"},"scopes": {- "notes:read": "Чтение заметок",- "notes:write": "Создание и редактирование заметок",- "transcriptions:read": "Чтение транскрипций",- "usage:read": "Просмотр использования"+ "notesRead": "Чтение заметок",+ "notesWrite": "Создание и редактирование заметок",+ "transcriptionsRead": "Чтение транскрипций",+ "usageRead": "Просмотр использования"},"revoke": {"button": "Отозвать",diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.jsonindex 70d40a041..3300ed266 100644--- a/src/locales/zh-CN/translation.json+++ b/src/locales/zh-CN/translation.json@@ -2021,6 +2021,14 @@"nameLabel": "密钥名称","namePlaceholder": "例如:我的集成","scopesLabel": "权限",+ "expiryLabel": "有效期",+ "expiryOptions": {+ "never": "永不过期",+ "30days": "30 天",+ "60days": "60 天",+ "90days": "90 天",+ "1year": "1 年"+ },"submit": "创建","cancel": "取消"},@@ -2032,10 +2040,10 @@"done": "完成"},"scopes": {- "notes:read": "读取笔记",- "notes:write": "创建和编辑笔记",- "transcriptions:read": "读取转录",- "usage:read": "查看使用情况"+ "notesRead": "读取笔记",+ "notesWrite": "创建和编辑笔记",+ "transcriptionsRead": "读取转录",+ "usageRead": "查看使用情况"},"revoke": {"button": "撤销",diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.jsonindex 5f3a8b164..d1735ce59 100644--- a/src/locales/zh-TW/translation.json+++ b/src/locales/zh-TW/translation.json@@ -2021,6 +2021,14 @@"nameLabel": "金鑰名稱","namePlaceholder": "例如:我的整合","scopesLabel": "權限",+ "expiryLabel": "有效期限",+ "expiryOptions": {+ "never": "永不過期",+ "30days": "30 天",+ "60days": "60 天",+ "90days": "90 天",+ "1year": "1 年"+ },"submit": "建立","cancel": "取消"},@@ -2032,10 +2040,10 @@"done": "完成"},"scopes": {- "notes:read": "讀取筆記",- "notes:write": "建立與編輯筆記",- "transcriptions:read": "讀取轉錄",- "usage:read": "檢視使用情況"+ "notesRead": "讀取筆記",+ "notesWrite": "建立與編輯筆記",+ "transcriptionsRead": "讀取轉錄",+ "usageRead": "檢視使用情況"},"revoke": {"button": "撤銷",diff --git a/src/services/ApiKeysService.ts b/src/services/ApiKeysService.tsindex 6375d4858..68b6bed1b 100644--- a/src/services/ApiKeysService.ts+++ b/src/services/ApiKeysService.ts@@ -14,6 +14,12 @@ interface CreateApiKeyResponse extends ApiKey {key: string;}+interface CreateApiKeyOptions {+ name: string;+ scopes: string[];+ expiresInDays?: number | null;+}+async function listApiKeys(): Promise<{ keys: ApiKey[] }> {const res = await fetch(`${OPENWHISPR_API_URL}/api/api-keys/list`, {credentials: "include",@@ -22,12 +28,20 @@ async function listApiKeys(): Promise<{ keys: ApiKey[] }> {return res.json() as Promise<{ keys: ApiKey[] }>;}-async function createApiKey(name: string, scopes: string[]): Promise<CreateApiKeyResponse> {+async function createApiKey(options: CreateApiKeyOptions): Promise<CreateApiKeyResponse> {+ const body: Record<string, unknown> = {+ name: options.name,+ scopes: options.scopes,+ };+ if (options.expiresInDays != null) {+ body.expires_in_days = options.expiresInDays;+ }+const res = await fetch(`${OPENWHISPR_API_URL}/api/api-keys/create`, {method: "POST",headers: { "Content-Type": "application/json" },credentials: "include",- body: JSON.stringify({ name, scopes }),+ body: JSON.stringify(body),});if (!res.ok) throw new Error(await res.text());return res.json() as Promise<CreateApiKeyResponse>;@@ -45,7 +59,7 @@ async function revokeApiKey(id: string): Promise<{ revoked: true }> {}export { listApiKeys, createApiKey, revokeApiKey };-export type { ApiKey, CreateApiKeyResponse };+export type { ApiKey, CreateApiKeyResponse, CreateApiKeyOptions };export const ApiKeysService = {list: listApiKeys,