Files
romm/frontend
Terri e964bbec88 feat(saves): sync saves for physical games by rom_id (#5862)
**Description**

Physical games (`is_physical` ROMs, such as Steam games added by hand)
have no files. Every snapshot channel keys to a ROM file, so sync
refused saves for these games.

A channel on a physical game now keys to the game's `fs_name` at size
-1, which no file has, so it never matches a real file's key. `fs_name`
is unique per platform for physical games, so the existing key columns
hold it and no migration is needed. A push also has to match the
channel's platform, since games on other platforms can share a name.

The push, channel create, attach and channel feed routes accept `rom_id`
in place of `rom_file_id`, for physical games only. Any other game
returns 422, and a game the caller can't see returns 404. A legacy `POST
/api/saves` upload for a physical game lands in that game's channel.

Channels follow the game:

- Deleting a physical game detaches its channels, as with any ROM.
- Adding it again with the same name, or renaming another physical game
to that name, reattaches them.
- Changing its `fs_name` moves its channels to the new key.

Title extraction and sigil work don't run for physical games. A save's
identity hash is its full content hash, since the emulator rule that
leaves out `.rtc` clock members doesn't apply to files a PC game writes.

Snapshot backups left by a deleted channel only come back when a scan
finds a file with their SHA-1, so a physical game's backups don't return
when it is added again.

```mermaid
flowchart LR
    P[request] --> F{rom_file_id or rom_id}
    F -->|rom_file_id| RF[visible ROM file] --> K1["FileKey.of_file (sha1, name, size)"]
    F -->|rom_id| R[visible ROM]
    R -->|is_physical| K2["FileKey.of_physical (fs_name, size -1)"]
    R -->|not physical| E[422]
    K1 --> C[channel on the same platform]
    K2 --> C
```

> AI Disclosure
>
> Planning and implementation supported by Claude Code.

**Checklist**

- [x] I've tested the changes locally
- [x] I've updated relevant comments
- [ ] I've assigned reviewers for this PR
- [x] I've added unit tests that cover the changes

#### Screenshots (if applicable)

No UI change.
2026-12-04 08:14:35 -05:00
..
2026-05-30 20:53:52 -04:00