Repository navigation
File versions in the Craft Cloud app, through the agent - #28
Open
Skyfuller1303 wants to merge 9 commits into
Open
Skyfuller1303 wants to merge 9 commits into
Skyfuller1303 wants to merge 9 commits into
Conversation
Adds the request and answer types of GET /nodes/{id}/history and POST /nodes/{id}/restore, the opaque history cursor with a single accepted spelling, and the paging limits (default 50, at most 200).
history() pages a file's versions newest first by (seq, id) with an exclusive cursor. restore_version() records a new version with the content of an old one as an ordinary update, checking the source, the current version, deletion and live documents under the same space lock as a commit. No migration is needed.
GET /api/v1/nodes/{id}/history and POST /api/v1/nodes/{id}/restore, resolved in the caller's own space. A stale expected_version answers 409 conflict. Covers permissions, paging, conflicts, restoring old and missing versions, and parallel restores in the API tests.
Updates the API table and the milestone note in the sync design, and adds a short section to the server guide.
A history page now reads versions through an index on (space_id, node, seq, id) in the order of the query, so the page size bounds the work. The migration adds the index on both databases. The restore note in the sync design no longer claims the engine prefers a newer live-document state: a restore is an ordinary new version and files with a live document are refused.
Types for the agent's /v1/files/history and /v1/files/restore in crates/api, and the blocking client calls file_history and restore_file in crates/app. The app crate still depends on api only.
GET /v1/files/history and POST /v1/files/restore take a path relative to the sync root, validate each component, resolve it in the saved sync state and forward to the server; unknown or unsynced paths are 404, paths outside the root and folders 400, server errors pass through typed and a server 401 becomes 409 needs_you. A successful restore asks for a normal sync pass; the agent never writes the file itself.
A File versions button on the signed-in screen opens a screen with a path field, the file's versions newest first and paged (date, size, device) and a confirmed restore. A conflict reloads the list and says so, refusals are explained, stale answers are dropped by tickets, a restore is refused while a page is loading, and the path is sent exactly as typed. The signed-in snapshots are redrawn with the new button.
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.
Stacked on #21 (version history and restore): this branch contains #21's commit; the diff of this PR alone is the last four commits. #21 adds the server routes; this makes them usable from the Craft Cloud app, through the agent (desktop → agent local API → server), as the layering requires.
What
Agent local API:
/v1/files/historypath, optionalcursorandlimit/v1/files/restore{path, version, expected_version}Name::new(no.., absolute paths, drive letters, NUL or reserved names). It then resolves the path in its saved sync state. Only synced files are forwarded:409 needs_you, like the other signed-in routes. The usual Host/Origin/token guard and body limits apply.Types in
crates/api/src/local.rs, and blocking callsfile_historyandrestore_fileincrates/app.appstill depends onapionly.Craft Cloud app: a "File versions…" button on the signed-in screen opens a Versions screen with a path field.
docs/agent.mdlists the two routes.Assumptions (please confirm or redirect)
Testing
cargo fmt --all -- --check,cargo check --workspace --all-targets --locked,cargo clippy --workspace --all-targets --locked -- -D warnings.--test local_api(14 tests, against a real server on loopback) and--lib(173 tests). Thelocal_apitests cover:expected_version(409);cargo test -p craft-cloud-app,-p craft-cloud-api -p craft-cloud-proto.--lib -- --test-threads=1(59 tests):versions-empty.png,versions-loaded.pngandversions-confirm.png;Not tested