feat(save/latest): expose payload format on latest-save responses#20
Open
terafin wants to merge 1 commit into
Open
feat(save/latest): expose payload format on latest-save responses#20terafin wants to merge 1 commit into
format on latest-save responses#20terafin wants to merge 1 commit into
Conversation
GET /save/latest returns {exists, sha256, version, id} but not the
payload's file type. Sync helpers that key "latest" on slotName +
recency can mistake a small, newer companion file for a newer revision
of a different component sharing the same slot — notably Game Boy
battery saves (.srm) and RTC saves (.rtc), which a helper may store
under the same slotName. The newer 8-byte .rtc then wins "latest" and
clobbers the 32 KB .srm.
Add a bare lowercase `format` field (e.g. "srm", "rtc") to every
exists:true /save/latest response, derived from the canonical record's
payload extension, so helpers can compare it against the local target
file's extension and skip-on-mismatch. Additive + backward-compatible.
Signed-off-by: terafin <terafin@users.noreply.github.com>
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.
What
Adds a bare lowercase
formatfield (e.g."srm","rtc") to everyexists: trueresponse fromGET /save/latest, derived from the canonical record's payload extension.Why
/save/latestcurrently returns{exists, sha256, version, id}— enough to detect a newer revision, but not the payload's file type. A sync helper that keys "latest" onslotName+ recency can mistake a small, newer companion file for a newer revision of a different component that shares the same slot.The concrete data-loss case: Game Boy / GBC saves where a helper stores the battery save (
.srm, ~32 KB) and the RTC save (.rtc, 8 bytes) under the sameslotName. The.rtcis written later, so it wins "latest" — and a naive helper then treats it as the newest revision of the slot and clobbers the.srm.Exposing
formatlets a helper compare the canonical record's extension against the local target file's extension and skip-on-mismatch, instead of round-tripping throughGET /saves/{id}(whose response shape doesn't carry the extension either).How
saveRecordFormat(rec saveRecord) stringhelper:strings.TrimPrefix(strings.ToLower(filepath.Ext(rec.PayloadFile)), ".")."format"to all threeexists: true/save/latestresponses (standard, PlayStation-projection, N64-controller-pak paths). The data is already in hand at eachwriteJSONsite.formatare unaffected.Tests
save_format_test.go— 6 cases (.srm/.rtc, uppercase normalization, no-extension, empty, multi-dot).go build ./...,go vet ./cmd/server/, andgofmtall clean.