feat(webui): expose transactional backup restore

Replace route-local restore writes with the core transaction and map preflight, rollback, and post-commit cleanup failures to precise HTTP responses. Treat only ENOENT as a missing export file and return transaction, restored, skipped, migrated, and restart facts.

Update the settings panel to describe the full sensitive configuration group, avoid restart guidance for empty plans, and reload settings after both successful and failed imports so the UI reflects committed disk state. Add HTTP regression coverage for export and restore error semantics.
This commit is contained in:
DrSmoothl committed 2026-07-15 16:12:51 +08:00
1 parent ccbee78cc7
commit bd9236e3fa
7 files changed
+305 -102

No files matched your search

-24
View File
@@ -101,11 +101,6 @@ export function buildBackup(
return { version: BACKUP_VERSION, app: BACKUP_APP, createdAt, files };
}
/** Validate a parsed bundle wholesale — any defect rejects the whole import. */
export function validateBackup(parsed: unknown): { ok: true; backup: Backup } | { ok: false; error: string } {
return validateBackupEntries(parsed, () => false);
}
function validateBackupEntries(
parsed: unknown,
skipEntryValidation: (spec: BackupFileSpec) => boolean,
@@ -132,25 +127,6 @@ function validateBackupEntries(
return { ok: true, backup: { version: BACKUP_VERSION, app: BACKUP_APP, createdAt: typeof b.createdAt === 'string' ? b.createdAt : undefined, files: files as Record<string, BackupEntry> } };
}
/**
* Decode a validated bundle for the legacy HTTP restore path. The production
* route switches to restoreBackup once the transaction module is introduced.
*/
export function planRestore(
backup: Backup,
opts: { restoreCredentials: boolean },
): { restore: Array<{ name: string; data: Buffer }>; skipped: string[] } {
const restore: Array<{ name: string; data: Buffer }> = [];
const skipped: string[] = [];
for (const [name, entry] of Object.entries(backup.files)) {
const spec = specFor(name);
if (!spec) { skipped.push(name); continue; }
if (spec.credential && !opts.restoreCredentials) { skipped.push(name); continue; }
restore.push({ name, data: Buffer.from(entry.data, entry.encoding) });
}
return { restore, skipped };
}
export interface PreparedRestoreFile {
name: string;
data: Buffer;