diff options
| author | Anwarul Islam <anwaarulislaam@gmail.com> | 2025-07-18 08:30:42 +0600 |
|---|---|---|
| committer | Anwarul Islam <anwaarulislaam@gmail.com> | 2025-07-18 08:30:42 +0600 |
| commit | c3caefc001e1ea6a7e5626acb1fe1054fa00a56a (patch) | |
| tree | 1780e09a517612acc9a53ca94ddb7577705947a4 /apps/web/src/components/keybinding-editor.tsx | |
| parent | 8e4661951d214f917357caef9d2895f2a4f7eb1e (diff) | |
| download | opencut-c3caefc001e1ea6a7e5626acb1fe1054fa00a56a.tar.gz | |
feat: enhance keybinding import validation and improve error handling
Diffstat (limited to 'apps/web/src/components/keybinding-editor.tsx')
| -rw-r--r-- | apps/web/src/components/keybinding-editor.tsx | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/apps/web/src/components/keybinding-editor.tsx b/apps/web/src/components/keybinding-editor.tsx index 8735c504..bc98c5fd 100644 --- a/apps/web/src/components/keybinding-editor.tsx +++ b/apps/web/src/components/keybinding-editor.tsx @@ -224,10 +224,21 @@ export const KeybindingEditor = ({ reader.onload = (e) => { try { const config = JSON.parse(e.target?.result as string); + // Validate config structure + if (!config || typeof config !== "object") { + throw new Error("Invalid configuration format"); + } + + // Validate each keybinding + for (const [key, action] of Object.entries(config)) { + if (typeof key !== "string" || typeof action !== "string") { + throw new Error(`Invalid keybinding: ${key} -> ${action}`); + } + } importKeybindings(config); toast.success("Keybindings imported successfully"); } catch (error) { - toast.error("Failed to import keybindings file"); + toast.error(`Failed to import keybindings: ${error}`); } }; reader.readAsText(file); |
