MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / handleImportDatabase

Function handleImportDatabase

static/js/settings.js:665–704  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

663
664// 导入数据库
665async 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// 清理数据
707async function handleCleanup() {

Callers

nothing calls this directly

Calls 5

confirmFunction · 0.85
loadDatabaseInfoFunction · 0.85
successMethod · 0.80
errorMethod · 0.80
jsonMethod · 0.45

Tested by

no test coverage detected