Skip to content

feat(restore): add restore-from-uploaded-ZIP and fix Windows users.db…#1341

Merged
perber merged 2 commits into
mainfrom
feat/restore-upload-windows-swap
Jul 26, 2026
Merged

feat(restore): add restore-from-uploaded-ZIP and fix Windows users.db…#1341
perber merged 2 commits into
mainfrom
feat/restore-upload-windows-swap

Conversation

@perber

@perber perber commented Jul 26, 2026

Copy link
Copy Markdown
Owner

… swap

Adds POST /restore/upload with a configurable max size (--restore-upload-max-size / LEAFWIKI_RESTORE_UPLOAD_MAX_SIZE) so a backup ZIP can be restored without CLI access. Also replaces the previous best-effort Windows warning with an actual fix: AuthService now suspends the UserStore's DB connection before a live restore renames users.db, avoiding a sharing-violation race on Windows.

… swap

Adds POST /restore/upload with a configurable max size
(--restore-upload-max-size / LEAFWIKI_RESTORE_UPLOAD_MAX_SIZE) so a backup
ZIP can be restored without CLI access. Also replaces the previous
best-effort Windows warning with an actual fix: AuthService now suspends
the UserStore's DB connection before a live restore renames users.db,
avoiding a sharing-violation race on Windows.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an admin workflow to restore a LeafWiki instance from an uploaded backup ZIP (no CLI access required) with a configurable upload size limit, and hardens live-restore behavior on Windows by ensuring users.db isn’t held open during the swap.

Changes:

  • Add UI + client API support for “restore from uploaded ZIP”, reusing the existing restore-status polling flow.
  • Add POST /api/admin/restore/upload with max-size enforcement and corresponding restore-manager support for staging uploaded ZIPs to disk.
  • Fix Windows restore sharing-violation race by suspending the auth user store’s DB connection prior to renaming users.db.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ui/leafwiki-ui/src/stores/restore.ts Adds triggerUpload(file) and factors polling logic into pollUntilDone() shared by both restore entrypoints.
ui/leafwiki-ui/src/stores/restore.test.ts Adds store tests covering upload-trigger flow, needs-intervention surfacing, and upload-call failure behavior.
ui/leafwiki-ui/src/locales/en/restore.json Adds new UI copy for the upload-restore section and confirmation dialog.
ui/leafwiki-ui/src/lib/api/restore.ts Adds triggerRestoreFromUpload(file) to POST multipart form data to /restore/upload.
ui/leafwiki-ui/src/features/snapshot/SnapshotSettings.tsx Adds UI section for selecting a ZIP and triggering restore-from-upload with confirmation dialog and toasts.
internal/wiki/restore/routes.go Registers and implements POST /restore/upload with multipart parsing, size limiting, and error mapping.
internal/wiki/restore/routes_test.go Adds HTTP wiring tests for upload restore, including 413-too-large, malformed multipart, and missing-file cases.
internal/wiki/restore/errors.go Adds restore-upload-related error codes for structured API responses.
internal/restore/manager.go Adds upload-restore entrypoint, upload staging to temp file, upload size accessor, and refactors run sequence to accept zip path.
internal/restore/manager_test.go Adds tests for max-upload-size behavior and restore-from-upload success/failure and cleanup semantics.
internal/restore/config.go Extends restore config with MaxUploadSizeBytes.
internal/core/auth/user_store.go Adds permanent suspend() behavior preventing lazy DB reconnect during restore swap window.
internal/core/auth/user_store_test.go Adds regression test ensuring suspend closes DB and blocks reconnect.
internal/core/auth/user_service.go Adds suspendStore() forwarding to UserStore.suspend().
internal/core/auth/auth_service.go Adds PauseUserStoreForSwap() and a localized “user store unavailable” error used during the restore swap window.
internal/core/auth/auth_service_replace_test.go Adds contract test ensuring pause-then-replace restores service functionality.
cmd/leafwiki/main.go Adds --restore-upload-max-size / LEAFWIKI_RESTORE_UPLOAD_MAX_SIZE wiring into restore manager config and updates usage text.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/wiki/restore/routes.go
Comment thread internal/restore/manager.go
Comment thread ui/leafwiki-ui/src/locales/en/restore.json Outdated
- Check for an already-running restore before staging the uploaded ZIP
  to disk, avoiding wasted disk I/O when the restore is rejected
- Clean up ParseMultipartForm's temp files after handling an upload
- Use "ZIP" consistently in restore upload UI strings
@perber
perber merged commit 5c06f84 into main Jul 26, 2026
9 checks passed
@perber
perber deleted the feat/restore-upload-windows-swap branch July 26, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants