fix: restore backup import after skills migration (#2980)

This commit is contained in:
muhamed hamed
2026-06-06 23:46:32 +03:00
committed by GitHub
parent eb840459f5
commit b03d934ec6
3 changed files with 159 additions and 15 deletions
+11 -3
View File
@@ -2120,14 +2120,22 @@ function initBackup() {
const btn = el('adm-importDataBtn');
btn.disabled = true; btn.textContent = 'Importing...'; msg.textContent = '';
try {
const text = await file.text();
const data = JSON.parse(text);
const text = (await file.text()).replace(/^\uFEFF/, '').trim();
let data;
try {
data = JSON.parse(text);
} catch (e) {
throw new Error('Invalid backup file: ' + e.message);
}
const res = await fetch('/api/import', {
method: 'POST', credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
});
const result = await res.json();
const result = await res.json().catch(() => null);
if (!result) {
throw new Error(`Import failed: server returned ${res.status}`);
}
if (res.ok && result.ok) {
msg.textContent = result.message || 'Import successful.'; msg.className = 'admin-success';
} else {