()
| 663 | |
| 664 | // 导入数据库 |
| 665 | async function handleImportDatabase() { |
| 666 | const file = elements.dbImportFile?.files?.[0]; |
| 667 | if (!file) return; |
| 668 | |
| 669 | const confirmed = await confirm( |
| 670 | `确定导入数据库文件「${file.name}」吗?系统会先自动备份当前数据库,再执行覆盖导入。` |
| 671 | ); |
| 672 | if (!confirmed) { |
| 673 | elements.dbImportFile.value = ''; |
| 674 | return; |
| 675 | } |
| 676 | |
| 677 | const originText = elements.importDbBtn.textContent; |
| 678 | elements.importDbBtn.disabled = true; |
| 679 | elements.importDbBtn.innerHTML = '<span class="loading-spinner"></span> 导入中...'; |
| 680 | |
| 681 | try { |
| 682 | const formData = new FormData(); |
| 683 | formData.append('file', file); |
| 684 | |
| 685 | const resp = await fetch('/api/settings/database/import', { |
| 686 | method: 'POST', |
| 687 | body: formData |
| 688 | }); |
| 689 | const data = await resp.json().catch(() => ({})); |
| 690 | if (!resp.ok) { |
| 691 | throw new Error(data.detail || `HTTP ${resp.status}`); |
| 692 | } |
| 693 | |
| 694 | const backupText = data.backup_path ? `,备份: ${data.backup_path}` : ''; |
| 695 | toast.success(`导入成功,已覆盖数据库${backupText}`); |
| 696 | await loadDatabaseInfo(); |
| 697 | } catch (error) { |
| 698 | toast.error('导入失败: ' + error.message); |
| 699 | } finally { |
| 700 | elements.dbImportFile.value = ''; |
| 701 | elements.importDbBtn.disabled = false; |
| 702 | elements.importDbBtn.textContent = originText || '📥 导入数据'; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | // 清理数据 |
| 707 | async function handleCleanup() { |
nothing calls this directly
no test coverage detected