feat(restore): add restore-from-uploaded-ZIP and fix Windows users.db…#1341
Merged
Conversation
… 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.
Contributor
There was a problem hiding this comment.
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/uploadwith 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.
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… 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.