Commit Graph

336 Commits

Author SHA1 Message Date
Georges-Antoine Assi
892657465f fix: stage the config fixture for e2e and address review findings
The e2e job copied only the fixture library, not the config.yml declaring its
platform-folder-first layout, so the seeder scanned an empty library.

Reject `.` and `..` template sections: no directory listing yields either, so a
template carrying one discovered nothing and marked the platform's roms missing.

Drop the cached `full_path` when either half is set. A scan reads it and then
renames the file in place, which left the cached pair stale.

Point `build_physical_fs_name` at the index 0126 actually creates.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 09:11:16 -04:00
Georges-Antoine Assi
a7ecfd96a9 feat!: make filesystem.structure the single library layout
`filesystem.structure` now spells out the whole layout rather than only the part
below a platform folder. A template is relative to the library root, `{platform}`
marks the platform folder, and `{game}` marks where a game begins.

Merge `{gameFile}` and `{gameDir}` into one `{game}` terminal. The information a
terminal carried was the depth, not the kind: at a declared level a file is a
game of its own and a folder is one multi-file game, which a stat answers. That
drops the two-template idiom for a level holding both, and `_discover_default_roms`
with it, since the default scan is now just `roms/{platform}/{game}`.

Retire the auto-detected `{platform}/roms` layout, along with
`filesystem.roms_folder` and `filesystem.firmware_folder`, which named one path
segment each that a template now contains. Both are refused at startup with the
template that reproduces the layout, so an instance that relied on either says so
instead of scanning an empty library and marking every rom missing. Firmware gets
its own `structure.firmware` key rather than following the rom layout implicitly.

`get_roms_fs_structure` keeps meaning the folder a platform's games start in, so
the `.physical` sentinel paths already in the database still resolve. Per-platform
overrides have to agree with `default` on where the platform folder sits;
relocating one platform needs platform discovery and the watcher to union several
roots, which is left out.

The setup wizard reports `library_ready` plus the configured template instead of
a `struct_a`/`struct_b` discriminator, so the banner shows the layout in force
rather than guessing it client-side.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 08:39:21 -04:00
Georges-Antoine Assi
f105622513 fix: address code review on the library structure unique index and relocation
Key the unique roms index on a sha256 digest of the full path. Indexing
(platform_id, fs_path, fs_name) directly is 5804 bytes of utf8mb4, which MySQL
rejects with ER_TOO_LONG_KEY and MariaDB silently demotes to a hash index; the
digest column keeps it a 260-byte BTREE on every supported driver. It is derived
by the same @validates hook that maintains the other fs_name columns, and
resynced explicitly in update_rom and convert_rom_to_folder.

Migration 0126 backfills the digest in one dialect-branched UPDATE. A Python
executemany right after the ADD COLUMN silently applies only its first parameter
set on mariadb-connector, leaving the rest NULL. test_migrations pins the SQL
expression to compute_full_path_hash so the two cannot drift.

Drop the relocation pre-pass. mark_missing_roms already runs before the identify
loop, so a moved file reaches get_matching_missing_rom, which requires all three
hashes to agree (or a title_id, covering non-hashable platforms), refuses
ambiguous matches, re-parses filename tags and emits over the socket. The
pre-pass duplicated it with a weaker CRC-only check, hashed every candidate
twice, compared folder sizes against a total that excludes filtered files, and
ran on QUICK scans.

Send uploads to a folder the platform's structure will actually discover, so the
next scan does not flag a fresh upload as missing, and refuse with a 400 when
only the user can pick the folder.

Make 0126's downgrade refuse when duplicate file names exist instead of deleting
the roms (and their saves, notes and collection membership) that carry them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 19:14:58 -04:00
Georges-Antoine Assi
4219f56f10 Merge branch 'master' into claude/kind-goodall-0b77y7
Conflict resolution notes:

- Locale rom.json: master sorted and reworked every file; took master's and
  re-inserted `location` / `location-copied` in sorted position. Added them to
  the new tr_TR locale.
- FSRom gained a required `fs_path`, so `build_hashless_fs_rom` now takes one
  and both call sites pass the rom's own path.
- `get_roms` keeps this branch's `_collect_fs_roms` discovery while adopting
  master's one-pass build and in-place sort.
- `mark_missing_roms` takes full paths and now also excludes physical games
  (master), and the scan loop keeps master's early missing-sync plus its
  restored-rom emit alongside this branch's relocation pass. The relocation
  filter now applies only to the identify loop, so a relocated rom is no longer
  re-flagged missing at the end of the scan.
- Relocation writes rom files through master's `sync_rom_files` (which replaced
  `purge_rom_files` / `add_rom_file`), so row ids and track metadata survive.
- Master's unique index on (platform_id, fs_name) contradicts this branch's
  premise that same-named files in different folders are distinct games.
  Migration 0126 widens it to (platform_id, fs_path, fs_name); physical games
  all share one folder, so a duplicate title is still rejected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 16:24:59 -04:00
Georges-Antoine Assi
b930a37448 Merge remote-tracking branch 'origin/master' into fix/ss-quota-breaker-recovery
# Conflicts:
#	backend/endpoints/roms/__init__.py
2026-09-06 22:54:48 -04:00
Georges-Antoine Assi
424b9cb75d refactor(search): pair each provider lookup with its name
The resolver took the provider names as a second tuple that had to stay in the
same order as the gather, which a reordered lookup would silently break. Pairing
the name with its coroutine follows the shape scan_handler already uses for
provider_fetches, and folds the gather into the resolver.

Also trims the comments and docstrings the review pass flagged as over-long.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 21:40:26 -04:00
Georges-Antoine Assi
6161f8057d refactor(screenscraper): report a short-circuited lookup per rom
A tripped breaker answers in ScreenScraper's place, so the empty match it
produces is not a miss and must not clear the rom's stored ss_id. The scan
learned that by sampling the module-wide is_breaker_tripped() at three points,
which reads another rom's trip as this rom's evidence.

SSHandler now raises ScreenScraperExhaustedError instead of swallowing the
breaker's error, carrying the match it would have returned so the name the
filename lookup derives locally (Switch title database, MAME, PS2 OPL) still
reaches the scan. fetch_ss_rom catches it the way it already catches
ScreenScraperRateLimitError, and drops ScreenScraper from attempted_sources
from a plain local, so the signal is exactly this rom's own lookups.

Also folds in a cleanup pass over the branch: the dead default_factory arm in
_ScanState.reset(), one home for the ssuserInfos.php path, asyncio.wait_for
around the quota probe so it cannot block behind a media download holding the
concurrency slot, and shared fixtures for the ScreenScraper tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 21:35:25 -04:00
Spinnich
0d7ce16d16 fix(screenscraper): let the daily-quota breaker recover
HTTP 431 means a ROM did not match and the daily cap on proposing unknown
ROMs for review is reached; scraping is unaffected, so it becomes a
not-found with one informational line per scan instead of a refusal that
takes the provider out.

HTTP 431 is really two answers at once and only one of them concerns the
scan. The scrape allowance (430) still trips a breaker, since every
remaining ROM would otherwise cost a round trip to be told the same thing,
but it now arms only after repeated refusals, ignores the ones already in
flight when a refusal was counted, and re-checks the free account endpoint
so it recovers without a scan to reset it. The account check can no longer
arm it at all.

A recoverable breaker can clear itself while a rom is still gathering its
other providers, so a complete rescan read it as having answered and wiped
the rom's id. It is now sampled where ScreenScraper is consulted.

The manual-match search gathers every provider without return_exceptions,
so it now swallows an exhausted ScreenScraper the way the scan lookups do.

Fixes #4123

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 15:08:18 +00:00
Georges-Antoine Assi
3cacb59ee4 refactor(streaming): give the duplicated rules one home each
Backend:
- One session-scan iterator (`_iter_session_keys` / `_iter_live_sessions`)
  replaces three copies of the Redis scan-and-decode loop, and
  `_get_live_session` replaces five independent "a drain marker is nobody's
  session" checks.
- `_abort_claim` replaces seven inlined claim-abort cleanups, so a new failure
  branch can no longer wedge a container and orphan a blank card.
- `_quiesce_container` and `_collect_exit_state` replace the stop-evacuate-wipe
  and guarded state-pull blocks written out in all three teardown paths. The
  `_record_termination` calls stay at the call sites: the three order it
  differently and each has its own reason.
- `_hold_reservation` / `_drop_reservation` collapse the two
  release-after-state-pull helpers into one, and absorb the third copy of that
  branch inlined in the released-session teardown.
- `_load_state_broker`'s two protocol branches were byte-identical, so it now
  takes its route from `_transfer_route`; `_raise_broker_http_error` and
  `_raise_broker_unreachable` replace the error translation copied into
  `_call_broker` and `_webstation_activate`.
- `_container_labels` builds the label map once per request rather than
  re-reading and re-parsing config.yml for every listed row.
- The joinable listing fetches each ROM once, through `get_rom_simple` rather
  than the `@with_details` query, for five columns.
- `store_memory_card_version` hands the hash it computed in memory to the scan,
  which was reading the archive back off disk to recompute it.
- `_prune_state_history` takes the history its caller already fetched.
- `playlist_files` in utils/m3u.py is now the one home for "which files are
  discs", shared by the download endpoint, the m3u generator and the swapper.

Frontend:
- `useActivityPresence` replaces the presence block copied verbatim from
  EmulatorJS.vue into Stream.vue.
- `MemoryCardNameDialog` replaces three copies of the same name-entry dialog.
- The two private axios error extractors give way to the `errorMessage` util,
  three hand-rolled spinners to `RSpinner`, six manual listener pairs to
  `useEventListener`, and five copy-on-write Set/Map trackers to `reactive`.
- `keepaliveHeaders` moves next to the interceptor that owns the CSRF header.
- The exit chord polls at 10Hz instead of every frame, the stage measures its
  offset once instead of per mousemove, `postToStream` reuses the frame list
  the attach pass walked, and the admin/home polls skip a hidden tab.
- `containerLabelForPlatform` on the store replaces the two `streamLabel`
  definitions that answered differently, and the stream/join action labels move
  onto useGameActions so the button and the menu cannot word them differently.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 08:54:32 -04:00
Georges-Antoine Assi
15233afcb1 Merge branch 'master' into feat/streaming-webstation
Conflicts and how they were resolved:

- `useGameActions`: master renamed `useCanPlay`'s `canPlay` to `canPlayLocal`
  and kept a local `canPlayStream`, while this branch moved `canPlayStream`
  into `useCanPlay` and folded it into `canPlay`. Kept this branch's shape and
  took master's `useScanTrigger()` call.
- `Player/Stream.vue`: kept this branch's force-release and session-poll block,
  and re-placed master's `useUnloadGuard(sessionActive)` next to the
  `sessionActive` watch.
- `locales/*/play.json`: kept both sides' keys, re-sorted.
- `__generated__/index.ts`: kept both sides' model exports, re-sorted.
- `test_config_loader.py`: kept both sides' tests.

Master took 0114 through 0118 while this branch was open, so its three
migrations are renumbered 0119-0121 and rechained after
`0118_rom_category_cheat_pg`, leaving alembic with a single head.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 07:49:12 -04:00
Georges-Antoine Assi
e57c5e471c Merge pull request #4353 from Spinnich/fix/complete-rescan-clears-attempted-ids
fix(scan): let a complete rescan clear the ids it rematched
2026-09-04 21:59:48 -04:00
Georges-Antoine Assi
3b2a9e3043 refactor(scan): share one failure path across the provider lookups
Every gathered provider already resolved through a single loop that logs the
failure, drops the source from the attempted set and falls back to an empty
match. SteamGridDB, which searches on the names the other providers produce and
so cannot join that gather, hand-wrote the same three steps again, and the
search endpoint hand-wrote a third copy. Extract the loop body into
`resolve_fetch` and route SteamGridDB through it.

In the search endpoint the cover gathers now tolerate exceptions instead, so a
failed lookup costs a thumbnail rather than the whole result set. That also
covers Libretro, whose lookup had no guard at all and could fail the request.

On the test side, the platform, rom and `fs_rom` scaffolding was written out
three times across the two scan tests; it now lives in `tests/handler/scan_stubs.py`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 20:58:27 -04:00
Georges-Antoine Assi
80185b225c refactor(scan): resolve platform folder names in both directions
Fold the folder name resolution into one home and make it case-insensitive
end to end.

Config folder names are lowercased as the config is parsed, so bindings,
versions and the built-in alias table are all matched the same way. A SNES/
folder now resolves, and a binding written GameCube: matches a gamecube/
folder.

Add resolve_fs_slug(), the inverse used to recover a renamed folder, which
replaces the two swapped dicts in scan_platform. Only slugs reached by
exactly one folder name are reversible, so recovery never guesses between
amiga500, amiga600 and amiga1200.

Validate system.platforms and system.versions through one helper that
rejects empty and non-string values, and treat a null block as empty rather
than exiting.

Restore the atari800 override in the example configs: its folder name is
itself a RomM slug, so it can never be an alias. A new test derives the
needed overrides from the alias table to keep the examples honest.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 17:32:07 -04:00
Spinnich
24bc4c221b fix(scan): don't let a failed lookup clear the id it couldn't check
A complete rescan clears the id of every source it consulted that came back
empty. That reads an outage as a conclusive miss for the providers that report
a failure as an empty match, so a rescan run while one was down wiped the id it
would otherwise have confirmed, hand-set ones included.

Each of those now reports the failure and leaves the tolerance to the caller,
which is what the gather loop's discard already assumed:

- Pouët, CSDb and Demozoo stop swallowing the 503 their own `_request` raises,
  and Pouët's title search raises it rather than answering "no unique title".
- SteamGridDB and Flashpoint stop catching `Exception` around a whole lookup;
  HLTB stops catching it around its search.
- ScreenScraper answers empty for every remaining ROM once its daily-quota or
  credentials breaker trips, so the scan reads that state off the service and
  drops it from the sources the rescan may clear.

SteamGridDB resolves outside the gather and so needs the discard at its call
site. Search keeps degrading to no thumbnail, since its cover art sits on top
of matches the other providers already produced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 20:49:51 +00:00
Spinnich
0d497018c7 fix(scan): let a complete rescan clear the ids it rematched
A complete rescan is documented as wiping every external id and matching
again from scratch, but it only wrote NULL for deselected sources. Selected
ones were assumed to reset implicitly by staying out of rom_attrs, which
merge then skips rather than nulling, so a provider that searched and found
nothing left its old (wrong) id in place.

Track the sources whose lookup actually ran and clear those too. A source
skipped because the platform carries no id for it never enters the set, so
hand-set ids on unmapped platforms survive, and a provider that raised or
hit the ScreenScraper rate limit is discarded again since it ruled nothing
out. SteamGridDB resolves after the reset block, so it clears its own id.

Fixes #4346

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 19:28:41 +00:00
Sam Dornan
7a54b1c6b0 Merge branch 'master' into feat/platform-folder-aliases
Master moved UniversalPlatformSlug to utils/platform_slugs.py so that naming
a platform no longer imports the metadata stack. The alias table and its
test now import the enum from there, and utils/platforms.py keeps both the
new leaf import and the resolver import.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 14:05:13 -05:00
Sam Dornan
994fddcbe5 feat(scan): resolve Batocera, RetroBat and ES-DE folder names to platforms
Frontend system folders such as gamecube, megadrive or n3ds only became
RomM platforms after the user copied a 100+ line system.platforms map into
config.yml. A built-in alias table now covers the folder names those
frontends use, seeded from the two example configs and cross-checked
against the upstream system lists.

Resolution order is unchanged for existing users: config bindings and
versions win, a folder name that already is a slug keeps matching itself,
and only then is the alias table consulted. The two call sites that
resolved folder names by hand share one resolver.

The example configs shrink to genuine overrides. The Batocera example
also mapped odyssey2 to the original Odyssey; the alias points at
Odyssey 2.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 10:59:20 -05:00
Georges-Antoine Assi
fbbadb7c86 refactor(scan): give the title id one resolver and one identity shape
The Tinfoil feed was left behind when `_switch_productid_format` changed
from taking a `re.Match` to taking a `str`, so `/feeds/tinfoil` raised a
TypeError for any Switch rom carrying a product id in its filename but no
titledb id. It went unnoticed because `feeds.py` sits outside the changed
files mypy sees.

That call site was reachable only because "prefer the id the scan read over
the one scraped from the filename" lived in a second helper above the lookup,
leaving each caller to remember it. The resolution now happens inside
`_switch_productid_format`, so the three providers and the feed all get it
without repeating a preamble.

Also:

- Move `SWITCH_PLATFORM_SLUGS` to the sigil adapter so `utils/switch.py`
  stops importing the metadata base handler. The cycle that import created
  was papered over with a function-local import, and `normalize_identity`
  now takes the fact it needs rather than the whole slug set.
- Merge a partial identity update onto the stored identity before
  normalizing it. Normalizing rewrites the whole triple, so a client sending
  only a title id was getting the derived base id next to its old save
  target.
- Add `RomIdentity.from_rom` so the triple has one home on the read side
  too, and drop `asdict` from `as_rom_attrs`.
- Hold the `SigilExtractionResult` on `TitleIdEmbedCandidate` instead of
  copying two of its fields.
- Drop a guard in `_rom_level_identity` that could not fire, derive once in
  `normalize_identity`, and return only the parse from `_rebuild_rom_files`,
  which already owns `fs_rom["fs_name"]`.
- Read the parsed config in the heartbeat rather than forcing a YAML
  re-parse per request, and make `SigilService.is_enabled` a classmethod
  like every other one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 10:57:36 -04:00
Georges-Antoine Assi
e19394e969 feat(scan): surface title id extraction and feed it to metadata matching
The optional binding used to no-op in silence: an absent sigil was
indistinguishable from a file with no title id. `SigilService.is_enabled`
plus `FILESYSTEM.TITLE_ID_EXTRACTION_ENABLED` on the heartbeat put the
feature on the same footing as every other optional capability, and give
a client of `PUT /roms/{id}/identity` a way to ask whether the server
reads binaries at all.

The extracted id also reaches the layer that already matches on Switch
product ids. Until now that layer could only scrape one out of the
filename, which made `embed_switch_title_ids` the de facto transport:
users had to let RomM rewrite their filenames for matching to improve.
`switch_product_id` prefers the id read from the binary, so extraction
helps everyone with the binding and the rename stays cosmetic.

MobyGames' `get_rom` takes the rom, like its IGDB and ScreenScraper
siblings, and the product-id lookup now happens only on Switch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 17:26:19 -04:00
Georges-Antoine Assi
355eee2190 refactor(scan): give the binary identity one shape and one writer
`RomIdentity` replaces the title_id / save_target / save_target_layout
triple that was spelled out separately on `ParsedRomFiles`, in `FSRom`,
and again in the scan's attribute merge.

`switch.normalize_identity` is now the single place that forces a Switch
id onto the base game's, which both the scan and `PUT /roms/{id}/identity`
call. The rule was written twice before, and the two copies disagreed
about what an update's save target should be. The endpoint keeps its
merge semantics: an omitted field is still left alone.

`get_rom_files` is a read again. It records which files can carry their
title id, and the new `embed_switch_title_ids` step performs the renames,
so writing to the user's library is a named call the scan makes rather
than a side effect smuggled out on a parse result.

The Switch family now lives in `utils/switch.py` in RomM's own terms,
instead of being recovered by filtering the sigil adapter's slug map.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 17:26:18 -04:00
Georges-Antoine Assi
7036ae0e9c Merge remote-tracking branch 'origin/master' into feature/sigil-title-ids 2026-09-02 16:34:48 -04:00
Georges-Antoine Assi
a7a15754b0 Merge remote-tracking branch 'origin/master' into claude/steam-metadata-provider
# Conflicts:
#	backend/config/__init__.py
#	backend/config/config_manager.py
#	backend/endpoints/heartbeat.py
#	backend/endpoints/responses/heartbeat.py
#	backend/endpoints/responses/rom.py
#	backend/endpoints/roms/__init__.py
#	backend/handler/database/roms_handler.py
#	backend/handler/metadata/__init__.py
#	backend/handler/scan_handler.py
#	backend/models/rom.py
#	backend/tasks/scheduled/scan_library.py
#	backend/watcher.py
#	env.template
#	frontend/src/__generated__/models/Body_update_rom_api_roms__id__put.ts
#	frontend/src/__generated__/models/DetailedRomSchema.ts
#	frontend/src/__generated__/models/MetadataSourcesDict.ts
#	frontend/src/__generated__/models/SimpleRomSchema.ts
#	frontend/src/locales/bg_BG/settings.json
#	frontend/src/locales/cs_CZ/settings.json
#	frontend/src/locales/de_DE/settings.json
#	frontend/src/locales/en_GB/settings.json
#	frontend/src/locales/en_US/settings.json
#	frontend/src/locales/es_ES/settings.json
#	frontend/src/locales/fr_FR/settings.json
#	frontend/src/locales/hu_HU/settings.json
#	frontend/src/locales/it_IT/settings.json
#	frontend/src/locales/ja_JP/settings.json
#	frontend/src/locales/ko_KR/settings.json
#	frontend/src/locales/pl_PL/settings.json
#	frontend/src/locales/pt_BR/settings.json
#	frontend/src/locales/ro_RO/settings.json
#	frontend/src/locales/ru_RU/settings.json
#	frontend/src/locales/tr_TR/settings.json
#	frontend/src/locales/zh_CN/settings.json
#	frontend/src/locales/zh_TW/settings.json
#	frontend/src/services/api/rom.ts
#	frontend/src/stores/heartbeat.ts
#	frontend/src/v2/components/EditRom/MetadataIdSection.vue
#	frontend/src/v2/components/GameDetails/RelatedGameCard.vue
#	frontend/src/v2/components/GameDetails/providers.ts
#	frontend/src/v2/components/Scan/ScanInfoDialog.vue
#	frontend/src/v2/utils/metadataProviders.ts
#	frontend/src/v2/views/Settings/ScanSettings.vue
2026-09-01 16:49:24 -04:00
Georges-Antoine Assi
9f7b273d70 fix(metadata): keep the scene lock across a failed provider lookup
scene_locked was computed only from the current scan's matches, so a Demozoo
outage on a rescan released the lock and let the catalogs write the cover, and
on a complete scan the name and summary, of an already identified production.
Base the lock on the persisted ids as well; deselecting the source on a
complete rescan clears them, which stays the way out.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-31 21:07:53 -04:00
Zach Clendenen
d9fe02bdb1 feat(memory-cards): store whole memory card images per user and emulator
Adds the MemoryCard/MemoryCardVersion models and migration, a database
handler, and the /api/memory-cards endpoints for creating, renaming,
sharing, downloading and uploading a card. Cards are scoped to a user
and emulator rather than a rom, since one card holds every game's saves.

Also streams zip entries when hashing so a compression bomb cannot
exhaust memory, and adds a CLI helper for importing an existing card.
2026-08-30 22:41:36 -05:00
nendo
e04b6035f2 Merge upstream master into feature/sigil-title-ids
Upstream took 0113, so the sigil migration rechains onto
0113_roms_locked_fields as 0114. The sigil build stage keeps its place
ahead of the emulator stage, which upstream renamed for js-dos.
2026-08-31 11:39:53 +09:00
Georges-Antoine Assi
fc46c3eb1c Merge branch 'master' into feat/demozoo-pouet-phase0
Renumber the two migrations onto master's head: 0108/0109 collided with
0108_roms_primary_region and 0109_rom_files_category_index, leaving the
chain with two heads. They are now 0114 and 0115 behind 0113.

Both rebuild the roms_facets sync triggers from a hardcoded column list,
so add the publishers and developers columns 0112 introduced. Without
them the rebuilt triggers would have silently stopped mirroring the two.

Adopt master's provider taxonomy. METADATA_PROVIDER_GROUPS now carries
demozoo, pouet, and csdb as catalogs, which replaces the branch's own
GENERAL_PROVIDER_KEYS set and feeds the setup wizard, the scan dialog,
and Settings from one registry. CSDb reaches the scan explainer for the
first time; it was already selectable there.

Regenerate the frontend types: DetailedRomSchema was missing the three
metadata blobs the backend has always declared on RomSchema, and the
blobs are now typed rather than Record<string, unknown>.

Correct the setup strings that still called the three sources enabled by
default, and sort the locale keys.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 21:32:11 -04:00
Georges-Antoine Assi
c0d01c58ee fix(metadata): harden the scene metadata handlers
Security review follow-ups on the Demozoo, Pouet, and CSDb handlers.

Default the three sources to off, matching every other provider. They
were the only ones defaulting to on, so an upgrade began contacting
demozoo.org, pouet.net, and csdb.dk on the next scan with no operator
opt-in, reachable through the unauthenticated metadata heartbeat.

Guard the bare id conversion in scene_id_or_none. str.isdigit() accepts
superscripts and other digits int() rejects, so a pasted "²" raised out
of the Edit ROM endpoint as a 500.

Filter the remote demozoo_url through http_url(). It was the only one of
the three URL fields taking a string from the API rather than building
one from a hardcoded template and an integer id.

Match a YouTube id against an explicit ASCII class. isalnum() is
Unicode-aware, so it accepted ids the embed URL never can.

Stream the CSDb response against a byte budget. The cap ran after the
whole body was already buffered, so it bounded the parse but not memory.

Catch defusedxml's refusals. EntitiesForbidden derives from ValueError
and ParseError from SyntaxError, so the existing handler caught neither
and an entity-declaring document raised out of production_from_xml.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 20:49:14 -04:00
nendo
64a1b57661 refactor(scan): name the save fields for what they address
`save_id` collided with two other meanings in the codebase: `Save` is a
model, and `DeviceSaveSync.save_id` is a foreign key to it. Neither is
what this field holds, which is the on-disk name an emulator gives a
game's saves. It becomes `save_target`, and `save_usage`, which said
nothing about what it decided, becomes `save_target_layout`. Both carry
a `doc=` so the meaning is at hand where the columns are read.

The per-file copies are gone. Nothing read `RomFile.save_id`, and the
per-file `title_id` and `title_version` only fed display chips, while
the category derived from the binary content type is what actually
drives update and DLC behaviour and stays. Save layout belongs to a
game rather than to one of its files, so a client can no longer read a
file's value and build a wrong directory from it.
2026-08-30 13:22:53 +09:00
Georges-Antoine Assi
c3e7aed3ea style: cut the artwork lock comments to the fact each one carries
The rationale for the locking scheme lives in the migration docstring and the
PR; the code only needs the part a reader cannot recover from it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 20:38:22 -04:00
Georges-Antoine Assi
5f9eb14719 refactor(resources): fetch the screenshots that are missing, not the whole set
Review of the artwork-provenance work turned up two gaps behind the cleanup.

The new skip gate compared files on disk against the number of urls, so a
permanently dead url held the count below the target forever and every scan
refetched the entire set. Going index by index refetches only what is absent,
and lets `_store_screenshot` report success instead of the caller stating the
file back off the disk it just wrote.

The SGDB block still read `path_cover_s` to decide whether a cover was hand
supplied, the inferred marker `locked_fields` exists to replace. That also
shielded scraped covers from a better ranked source, which is the behaviour
this branch set out to fix, so it now asks the lock like the block above it.

The rest is cleanup: drop the dead `screenshots_exist`, give the column one
normal form across its writers, hoist the duplicated clear-out dict in
`delete_rom_manuals`, and drop the blanket backfill UPDATE, since a NULL
already reads as "no locks" everywhere.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 19:56:39 -04:00
Georges-Antoine Assi
005db06525 Merge remote-tracking branch 'origin/master' into fix/artwork-provenance-update-scan 2026-08-29 19:21:27 -04:00
Sam Dornan
b2e3de4772 Merge branch 'master' into claude/steam-metadata-provider
Resolves the additive conflicts against master:

- config, handler registry and the roms endpoint imports keep both the
  Steam and the new UPC-lookup entries.
- Renumbers the Steam migration to 0113 (master took 0109) and rebases it
  onto 0112_publisher_developer_split.
- Syncs the migration's pre-Steam facet mirror list with 0112, which added
  publishers/developers to the roms_facets triggers.
- Groups SteamMetadata's publishers/developers with the shared provider
  keys, now that master has made them a shared field.
2026-08-29 16:36:58 -05:00
nendo
7e824d4977 Merge remote-tracking branch 'upstream/master' into feature/sigil-title-ids 2026-08-28 10:58:01 +09:00
Georges-Antoine Assi
c78424b2a8 fix: reject a duplicate physical game instead of suffixing its name
build_physical_fs_name probed for an existing row and appended " (2)", " (3)"
and so on, which silently minted a second entry for a title the platform
already had. Two copies of one physical game on one platform is not a library
anyone owns, and the unique index on (platform_id, fs_name) already says so.

Drop the loop and its per-creation SELECT: the sanitized name is the fs_name,
and a duplicate falls through to the IntegrityError handler the endpoint
already had. Reword its 409 accordingly, since a duplicate is now the ordinary
way to reach it rather than a race. The add-physical-game dialog already
surfaces `detail` in an error snackbar, so it needs no change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 07:32:18 -04:00
nendo
5425a227ab Merge upstream master into feature/sigil-title-ids
Upstream took 0108 through 0110, so the four sigil migrations rechain
onto 0110_walkthrough_docs as 0111 through 0114. RomFile keeps both the
title id index and upstream's new rom_id/category composite, and
models/rom.py keeps SaveUsage alongside the new document types.
2026-08-26 19:40:48 +09:00
Georges-Antoine Assi
08901ca3a9 cleanup: reuse, simplify and trim the physical-games feature
Backend:

- Drop the post-scan re-assert of is_physical/upc/fs_path in
  create_physical_rom; scan_rom already forwards them in rom_attrs. The test
  fake was written to drop those fields to exercise the dead path, so it now
  matches the real scan_rom contract.
- Extract build_hashless_fs_rom() and use it from both the physical endpoint
  and the scan socket, which built the same FSRom literal by hand.
- Return added_rom instead of re-fetching it; add_rom is already decorated
  with @with_details, so get_rom repeated the whole eager-load fan-out.
- Pair invalidate_filter_values_cache() with refresh_affected_smart_collections(),
  as every other rom-mutating endpoint does.
- Reword the 409 detail: build_physical_fs_name uniquifies the name, so an
  IntegrityError can only mean a concurrent add.
- upc_handler: inline the single-use base_url and hoist the minimum title
  length to a module constant.

Frontend:

- Load BarcodeScannerDialog lazily. GlobalDialogs is mounted on every page, so
  the static import chain put ZXing (~438 KB) in the eager layout chunk. The
  scanner's watcher now runs immediate/post so it still starts when mounted
  behind a v-if.
- Guard the scanner against a teardown that races the decodeFromConstraints
  await; closing during the permission prompt left the camera on and the
  decode loop running.
- Render the UPC scan trigger through RTextField's append-inner adornment
  instead of a hand-built flex row.
- Type the createPhysicalRom payload with the generated PhysicalRomCreateForm
  and drop the metadataSources argument, which had no caller.
- Declare @zxing/library directly; it was imported but resolved transitively.
- Drop two write-only refs, scope the reader local to startCamera, and trim
  comments that restate the code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-25 20:47:56 -04:00
Georges-Antoine Assi
69938b1cee add support for physical (DB only) games 2026-08-25 20:19:05 -04:00
Sam Dornan
ba00e0f270 refactor(steam): extract resolve_steam_rom so the match choice is testable
The ID-vs-filename decision sat in a closure inside scan_rom, out of reach
of a unit test. Lifts it to a module-level resolver, as LaunchBox already
does, and covers both scan types plus the stored-ID case.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 13:37:53 -05:00
Sam Dornan
16d9b361d8 fix(steam): refetch by stored app ID instead of re-searching
An UPDATE scan re-ran the fuzzy filename search even when the ROM already
carried a Steam ID, so a different app scoring above the similarity floor
could replace a match a user had pinned by hand. Refetch the stored ID
instead, as moby, ss, sgdb and flashpoint already do.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 13:37:53 -05:00
Sam Dornan
6a8cb34645 feat(steam): add the Steam storefront as a metadata provider
Steam covers the PC platforms RomM otherwise has thin metadata for, and
its store payload is provider-grade on its own: title, description,
portrait capsule art, screenshots, genres, developers, publishers,
release date and Metacritic score, with no API key.

Valve documents no storefront API, so this reads the two endpoints that
back the store's own search box and app pages, paced well under the ~200
requests per 5 minutes they tolerate. Every failure path degrades to "no
match" rather than aborting a scan, and the provider is opt-in behind
STEAM_API_ENABLED, matching HowLongToBeat and Flashpoint.

Matching is gated on the platform slug so the three PC platforms are the
only ones that spend a request. The storefront's search index carries
DLC, soundtracks and tools alongside games, so hits are filtered by type
and then confirmed against the app page, which is the only place a demo
or a video is distinguishable from a game. A (steam-12345) filename tag
pins a match by hand when the title is ambiguous.

SteamMetadata reuses the key names the other providers already use for
the values they share, so wiring Steam into the generated facet columns
later is a SQL change with no stored-row reshaping.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 13:35:42 -05:00
Georges-Antoine Assi
7f8f87e538 refactor(hltb): inline the HowLongToBeat match resolution
The helper had a single caller, so the stored-ID branch now sits in
fetch_hltb_rom like the Flashpoint and MobyGames fetchers. Its tests move
with it and drive the same six cases through scan_rom.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 11:27:54 -04:00
Sam Dornan
3b9acc3e34 docs(hltb): state which scans resolve by stored ID
The docstring read as though a stored ID always wins, but the ID branch is
scoped to UPDATE and to UNMATCHED with no metadata. Say so, and cover the
COMPLETE fall-through with a test so the exclusion reads as deliberate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 18:26:31 -05:00
Sam Dornan
6932abc5a9 fix(hltb): keep a pinned HowLongToBeat match through a rescan
fetch_hltb_rom called the fuzzy filename search unconditionally, so an
UPDATE scan re-guessed the match even when rom.hltb_id was already set. Any
other game scoring above the similarity floor replaced an ID the user had
pinned by hand in Edit ROM.

get_rom_by_id has existed since #2926 was fixed, but only the Edit ROM path
called it. Extract resolve_hltb_rom as a module-level function, following
resolve_launchbox_rom, so the ID-first branch is covered by tests rather
than trapped in a closure over scan_rom's frame.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 18:06:07 -05:00
Sam Dornan
5289899aae fix(scan): record hand-supplied artwork explicitly
The upload marker was inferred: an artwork upload stores the file and
clears url_cover, so a stored cover path with no url meant "user
supplied this". That signal cannot survive. get_cover returns no path
when the file is missing and the scan writes that straight back to
path_cover_s, so a single scan run while the resources volume is
unavailable erases it. The next scan reads the row as having no cover at
all, adopts the provider url, and replaces the user's cover with
provider art once storage returns. A resources volume left out of a
container recreate is enough to lose every uploaded cover in a library.

path_cover_s cannot carry this. It tracks the filesystem and is
reconciled on every scan; provenance has to outlive the file.

locked_fields records it durably instead. Uploading artwork or a manual
locks the field, and removing it, redownloading it, or naming a source
url releases it again. A complete rescan clears the locks along with the
resource files it deletes, so a lock can't point at a file that is gone
and block its replacement.

The migration backfills the old inferred marker, which is the last point
at which it can still be read. Without it the first scan after upgrading
would replace every uploaded cover. Manuals are deliberately not
backfilled: an uploaded manual and a scraped one share a path and
neither clears url_manual, so any guess would be wrong for half the
rows. Manuals stay pinned by the scan and are marked from here on.

Backfill verified on MariaDB and PostgreSQL against rows in the old
shape, covering uploaded, scraped, coverless, and null-url cases.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 10:11:19 -05:00
Sam Dornan
7a3b67e094 fix(scan): let update scans replace provider-written artwork urls
An update scan pinned url_cover to the stored value whenever a cover file
existed, and pinned url_screenshots whenever any were stored. Because
scan.py gates the download on `_added_rom.url_cover != rom.url_cover`,
forcing those equal made the gate structurally unreachable, so a freshly
resolved url could never reach the download step.

Uploading artwork clears url_cover while keeping path_cover_s, so that
pairing distinguishes a hand-supplied cover from a scraped one. Test for
it directly instead of for file existence, which is true of scraped
covers too. Screenshots have no upload path, so the fresh set always
wins.

name, summary and url_manual stay pinned: none of them can yet tell a
hand-edited value from a provider-written one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 10:11:15 -05:00
Axel Quack
45bcb2bed3 feat(metadata): add Demozoo, Pouët, and CSDb handlers
Identify demoscene productions as ROMs via filename tags, Edit-ROM
id/URL paste, Demozoo ?title= + rank, unique Pouët search.php 302,
and CSDb XML by id (no HTML scrape). Scene ids lock name/summary/cover
so game catalogs cannot attach a similarly titled box.

CSDb XML is parsed with defusedxml and capped; screenshot and extra
links are stored only when they are http(s).

Fixes rommapp/romm#1796 (Phase 0–2).
2026-08-17 08:59:54 +01:00
Sam Dornan
f22aadf77a fix(scan): re-read filename tags on a complete rescan
A rom parsed its filename tags when it was first inserted and never again,
so a change to parse_tags only reached rows scanned after it. The freshly
parsed values were built for every rom but only consumed on the insert
path, and scan_rom reseeded the tag columns from the existing row, so no
scan type could refresh them.

A complete rescan (or an explicit per-rom selection) now writes them back.
A hashes rescan still doesn't, since it is scoped to re-reading file bytes.

scan_rom also carries "version" forward now. It was the one tag column
missing from its attrs, so a re-parsed version would have been dropped, as
the value written by the reassociation path already was.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 21:38:12 -05:00
nendo
95f30b409c Merge upstream master into feature/sigil-title-ids
Resolve conflicts:
- rom_files/roms indexes: union the title-id index with upstream's new
  hash-search indexes.
- scan.py: keep upstream's ScreenScraper scan refactor, retaining the
  LIBRARY_BASE_PATH and UniversalPlatformSlug imports the body still uses.
- cleanup_orphaned_resources tests: take upstream's version.
- Renumber the sigil migrations onto upstream's 0107 head as 0108/0109/0110
  so the alembic chain stays single-headed.
2026-08-17 03:57:25 +09:00
Sam Dornan
ff2026c66d fix(launchbox): retry by filename when a Playmatch ID resolves to nothing
A scan preferred the LaunchBox ID Playmatch reports and, when the metadata
store could not resolve it, stopped there. Playmatch answers with an ID for
nearly every ROM on some platforms (38/40 sampled N64 dumps, 39/40 SNES,
against 4/40 GBA), so those platforms never reached the filename lookup and
were left with no LaunchBox metadata at all, while a manual match still
found the game.

The branch moves out of the scan closure into `resolve_launchbox_rom` so it
can be tested without a database. An ID already stored on the ROM is still
never traded for a filename guess: it usually came from a manual match.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:50:24 -05:00
Georges-Antoine Assi
117f420dca Merge pull request #4013 from rommapp/fix/hashes-scan-rematches-hasheous
fix(backend): re-run the Hasheous hash lookup on a hashes scan
2026-07-30 19:23:56 -04:00