Commit Graph

8 Commits

Author SHA1 Message Date
Georges-Antoine Assi
e81bcef430 review: only advertise cloud-sync assets their path resolves back to
Addresses Greptile's review on #3904: a manifest path carries no platform,
so a same-named ROM on another platform (or a save whose file name matches
no ROM) was advertised under a path GET/PUT/DELETE resolve elsewhere.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 08:26:14 -04:00
Georges-Antoine Assi
fdc7ba2b33 Merge remote-tracking branch 'origin/master' into feat/retroarch-cloud-sync
Resolve semantic conflicts with master:

- `zip_cache._ensure_zipfile_writable` is now public `ensure_zipfile_writable`.
- `get_saves()`/`get_states()` take `rom_ids` instead of `rom_id`.

Also ignore the cloud-sync test artifact directories.
2026-09-08 16:57:07 -04:00
Mustafa YAMAN
f3f56880b1 feat(cloud-sync): bundle PPSSPP's PSP save-folder layout for RetroArch sync
PPSSPP doesn't save a single file per game like every other core -- it
mirrors a real PSP memory stick under saves/<core>/PSP/SAVEDATA/<slot>/
as several small files (PARAM.SFO, the actual save data, ICON0.PNG, ...)
that only make sense as a set, plus saves/<core>/PSP/SYSTEM/CACHE/ holds
pure engine caches with no save data at all. Neither fits the existing
one-WebDAV-path-per-asset model.

Ports the retroarch-webdav-romm shim's pspSave.ts approach: a save
folder's files are bundled into a single zip stored as one RomM Save
(slot=None), and unbundled again for GET/manifest purposes. The rom is
resolved from the folder's PARAM.SFO TITLE (normalized-matched against
roms on the psp platform) with PSP_SERIAL_MAP as an explicit override and
fallback for titles that don't normalize-match automatically. Files that
arrive before the folder resolves (RetroArch doesn't guarantee PARAM.SFO
lands first) are buffered on disk until it does, and merged in once
resolved.

Manifest lists each bundle member as its own {path, hash} entry, since
RetroArch diffs per-file, not per-bundle.

Also fixes a latent zipfile bug this surfaced: zipfile_inflate64 (pulled
in elsewhere for ROM archive reading) replaces zipfile._get_compressor
with a signature CPython 3.13's own ZipFile.writestr() can't call --
RomM already has a shim for this (utils/zip_cache.py's
_ensure_zipfile_writable), just needed calling here too.
2026-07-24 17:51:11 +03:00
Mustafa YAMAN
4f03ded712 fix(cloud-sync): sync a state's screenshot alongside the state itself
RetroArch uploads a PNG screenshot alongside every state it syncs, named
`<state file name>.png` (e.g. `test_rom.state.png`). Verified live: this
file name doesn't match RetroArch's own `.state[N]`/`.state.auto` slot
pattern once naively split on the last dot ("test_rom.state" is not any
ROM's name), so `_resolve_rom` failed and every screenshot upload 409'd.

game_name_from_file_name now strips a trailing `.png` before applying the
existing state-suffix stripping, so it resolves the owning ROM the same way
it would for the state itself. Screenshots have no ROM-name-derived slot of
their own -- they ride along with whichever state `resolve_state_by_slot`
already picked for that (rom, emulator, slot), via the new
`resolve_state_screenshot_by_slot`, and are stored as a Screenshot (RomM's
own state-thumbnail model), not a State.

build_manifest now also advertises a `<canonical state name>.png` entry
for any state that has one attached, so RetroArch's own upload of it
succeeds and diffs correctly on subsequent syncs instead of failing (and
retrying) forever.
2026-07-24 16:51:13 +03:00
Mustafa YAMAN
2c727c9c5b fix(cloud-sync): remap web-player states into RetroArch's numbered load slots
States have no `slot` column (unlike saves), so a state created through
RomM's own web player -- named with a display label and timestamp, not a
RetroArch slot number -- was surfaced in the cloud-sync manifest under its
raw file name. Verified live: RetroArch's Load State menu only ever offers
numbered slots 0-999, so a synced file named otherwise downloads
successfully but is never reachable from that menu.

Mirrors the reasoning already used for the retroarch-webdav-romm shim
project's manifest builder: states are grouped by (rom, emulator, slot
suffix) via the file name's trailing .state/.state<N>/.state.auto pattern,
and the newest state in each bucket -- regardless of whether it came from
RetroArch itself or the web player -- is advertised under the canonical
name RetroArch's own upload for that slot would carry. GET/DELETE resolve
that canonical name back to the same bucket via resolve_state_by_slot, so
serving and deleting agree with what the manifest advertised even when the
underlying row's real file name differs.
2026-07-24 16:35:08 +03:00
Mustafa YAMAN
4c878817d6 fix(cloud-sync): normalize emulator casing between RetroArch and RomM
RetroArch's cloud-sync core-name segment uses its own directory casing
(e.g. "Snes9x"), while RomM's emulator field convention is the lowercase
libretro core id (e.g. "snes9x") -- the same convention its own web player
matches saves against exactly. Storing the raw RetroArch casing made a
synced save invisible in RomM's web player, and could hand RetroArch back
a folder name its local install never uses.

Adds a small translation table (ported from the community
romm-retroarch-sync project) plus a safe universal normalization for the
write direction. Cores outside the table round-trip unchanged rather than
guessing at an unverified casing.
2026-07-24 12:20:02 +03:00
Mustafa YAMAN
4bfe3481d3 feat(cloud-sync): support config/thumbnails/system as opaque per-user blobs
RetroArch's Cloud Sync also offers a config/, thumbnails/, and system/
category alongside saves/states, none of which belong to a ROM. The
previous behavior rejected them with 409 so RetroArch would keep retrying
locally instead of losing data. This stores them as plain per-user files
under CLOUD_SYNC_BLOB_BASE_PATH (FSCloudSyncBlobHandler) instead, namespaced
by user so two RetroArch installs syncing to the same RomM instance under
different accounts don't clobber each other's files, and includes them in
the manifest alongside saves/states.
2026-07-24 11:34:51 +03:00
Georges-Antoine Assi
fb2f44a582 feat(cloud-sync): serve RetroArch Cloud Sync over WebDAV
RetroArch's cloud-sync driver diffs a JSON manifest of {path, hash} entries
and then GETs/PUTs/DELETEs individual files, so it needs only a narrow slice
of WebDAV and never issues PROPFIND. Expose that slice at /api/cloud-sync so
save files and states sync straight into RomM's existing asset storage.

Assets are matched to a ROM by file name, and the optional core folder maps to
the emulator field that already namespaces asset storage. The router gates
itself rather than using @protected_route, so it can answer a 401 challenge
instead of a 403, and error responses carry no body because RetroArch's client
mishandles large ones.

Closes #2313

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 09:57:07 -04:00