Commit Graph

429 Commits

Author SHA1 Message Date
Georges-Antoine Assi
603e3b0c93 fix(sync): keep state screenshots separate per core
RetroArch names a slot's state the same under every core, and its
screenshot was filed per ROM, so two cores' `<rom>.state.png` shared
one file and one row. File them under a per-core screenshots folder,
upsert by path, and only match a state to a screenshot in its own core's
folder or the ROM-level one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 16:02:00 -04:00
Georges-Antoine Assi
7e7e5a671d refactor(sync): apply simplify pass
- Enforce the upload size cap on streamed bytes in the middleware, so
  chunked uploads to every guarded route are bounded, not just RetroArch
- Flag vanished assets missing_from_fs from the manifest instead of
  re-hashing them every sync
- Batch state screenshot lookups, filter PSP bundles in SQL, hash files
  in one thread hop, and read only the requested PSP bundle members
- Reuse remove_screenshot and content_hash_of_bytes, merge the save and
  state PUT branches, drop dead checks and trim docstrings and tests

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 15:50:49 -04:00
Georges-Antoine Assi
638a21f88b fix(sync): don't log missing files when hashing the RetroArch manifest
Every manifest read (GET and each PROPFIND) hashes every save and state
row, and failures aren't cached, so a DB row whose file is gone logged a
debug line on every sync. A missing file is expected there; other OSErrors
are still logged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 14:50:25 -04:00
Georges-Antoine Assi
49e8d380e9 refactor(sync): rename the RetroArch blob handler to retroarch_sync
FSRetroArchSyncBlobHandler becomes FSRetroArchSyncHandler, and
SYNC_RETROARCH_BLOB_BASE_PATH becomes SYNC_RETROARCH_BASE_PATH, stored
under /romm/retroarch_sync.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 14:20:06 -04:00
Georges-Antoine Assi
7c7f27d701 refactor(sync): mount RetroArch Cloud Sync under /api/sync/retroarch
The manifest protocol is RetroArch's own, so name it after RetroArch
rather than its WebDAV transport, and group it with the existing sync
code: endpoints/sync/ becomes a package with the RetroArch router as a
subroute, and the handlers move under handler/sync/retroarch/. Settings
move into the SYNC config section as SYNC_RETROARCH_*.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 14:07:39 -04:00
Georges-Antoine Assi
66fb93eca1 refactor(webdav-cloud-sync): rename cloud_sync to webdav_cloud_sync
Group the handler modules under handler/webdav_cloud_sync/ (sync_handler,
psp, emulator_names, browser) and rename the endpoint, blob handler, tests,
config settings, storage folders and cache keys to match. The route moves
from /api/cloud-sync to /api/webdav-cloud-sync.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 13:54:23 -04:00
Georges-Antoine Assi
0553dcae78 fix(cloud-sync): address Greptile and CodeQL review findings
- Resolve PSP folder paths from the same bundle set the manifest lists
  (visible ROM, unslotted, newest per folder), so GET/PUT/DELETE can no
  longer hit a slotted history bundle or a hidden ROM's bundle.
- Split validate_path's base-directory case out of its startswith guard,
  so CodeQL recognizes the guard as a py/path-injection sanitizer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 13:34:26 -04:00
Georges-Antoine Assi
d5d9196db3 refactor(cloud-sync): apply simplify pass
- Hoist the file MD5 onto FSHandler; drop the blob handler copy
- Share path splitting, slot recency, cached MD5 and ROM visibility helpers
- Remove dead code (get_state_by_path, RomFile.file_ids, unused params)
- Scope WebDAV rom listing to one query; look up a single platform by slug
- Query saves once per manifest and batch ROM name resolution
- Read only the requested PSP bundle member; hash bundles from memory
- Single separator-safe lexical check in validate_path; same joined-path
  validation in write_file_streamed
- Stop stripping + on ROM rename, the download path encodes it (#2746)
- Trim comments to the repo's comment rules

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:55:32 -04:00
Georges-Antoine Assi
9e7933ae97 fix(cloud-sync): apply code-review xhigh findings
- Bound /api/cloud-sync uploads with the asset size limit
- Cap PSP bundle member count and uncompressed size
- Keep PSP writes and deletes on the existing bundle row, one member at a time
- Match PSP bundles by exact folder, support the no-core-folder layout
- Reject . and .. PSP segments; map parse_sfo struct errors and write
  errors to 4xx
- Require ROMS_READ for roms/ browsing
- Clear missing_from_fs on overwrite
- Resolve state screenshots by exact name, never a gallery screenshot
- Round-trip unknown core folder names exactly
- Keep + allowed in the shared sanitizer, strip it only on ROM rename (#2746)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:31:51 -04:00
Georges-Antoine Assi
008dee6c27 ci: validate the joined write_file path for CodeQL
The remaining py/path-injection alerts flowed through write_file's
filename argument (cloud-sync blob PUTs), which only went through
os.path.basename. Validating the full directory + filename path routes
it through validate_path's normpath guard too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 10:53:24 -04:00
Georges-Antoine Assi
899f859a9b ci: satisfy bandit and CodeQL path-injection checks
Swap xml.sax.saxutils.escape for html.escape(quote=False), which bandit
does not flag as an XML parser import. Add a normpath + startswith guard
to validate_path so CodeQL recognizes it as a path-injection sanitizer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 10:34:37 -04:00
Georges-Antoine Assi
7808bf004b Merge remote-tracking branch 'origin/master' into feat/retroarch-cloud-sync
# Conflicts:
#	backend/handler/database/states_handler.py
#	backend/tests/utils/test_filesystem.py
2026-09-24 08:22:22 -04:00
Sam Dornan
b5e50a14cc feat(metadata): tag a dump from the flags ScreenScraper raises on it (#4666) 2026-09-23 07:14:46 -04:00
Sam Dornan
74c8e4bfb5 feat(metadata): read a fan translation's tag and target language (#4665)
* feat(metadata): read a fan translation's tag and target language

A translated dump is playable in the language it was translated into, but the
tag saying so was kept verbatim, so the rom was filed under no language at all
and the filter drawer grew one throwaway value per patch: "T+Eng1.1_RPGe" and
"T-Eng0.98_DeJap" are the same thing to a reader and two different facets to
the gallery.

The GoodTools, TOSEC and plain spellings now resolve to one "Translation" tag,
and the language the patch targets joins the rom's languages, so a Japanese
game translated into English answers a search for English and reaches an
emulator as English. A translation into a language RomM cannot name is still
tagged, and a tag that merely starts with "tr", like "Trainer", is left alone.

The group and patch version the raw tag carries are dropped, since nothing
reads them and keeping them is what splits the facet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC

* feat(metadata): read the spaced form of a GoodTools translation tag

"[T Fre]" separates with a space rather than a sign, and it is the spelling a
real ScreenScraper dump carries: its entry for "Super Mario Bros. (W) [T Fre]"
is flagged as a translation into French. The tag was read only as "T+Fre" or
"T-Fre", so that dump came out untranslated and unlanguaged.

A space carries no meaning of its own, unlike the sign, so this spelling counts
only when the word after it names a language: "(T Rex)" stays an ordinary tag.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC

* style(metadata): trim the translation alias comment to two lines

Greptile flagged it against the repo's comment discipline: four lines, and
the product as the actor.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC

* feat(metadata): resolve the short forms of a translation tag's language

"[T-En]" already resolved through the filename language vocabulary; the
non-ISO abbreviations "Ge", "Sp", "Du", "Gr" and "Jp" did not, so those
dumps were tagged without a language. Tests now cover both forms.

Also trims three comments and four test docstrings Greptile flagged
against the repo's comment discipline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC

* fix(metadata): stop reading a hyphenated word as a translation

"(T-Rex)" matched the GoodTools superseded form and became a Translation
tag. A superseded patch carries its version and group, so require that,
or a language the vocabulary names, before the bare "T-" form counts.

"[T+Tha]" still tags, since no ordinary word takes that shape.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC

* style(metadata): trim the translation regex comment to two lines

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4mTJZ63Bvafv3stpiGsHC

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 23:03:49 -05:00
Sam Dornan
ddd87ff554 feat(metadata): take region and language from the dump a hash matched (#4664) 2026-09-22 23:47:23 -04:00
Sam Dornan
552cf7c213 fix(config): show folder mappings whose folder name is not lowercase (#4676) 2026-09-21 19:52:40 -04:00
Sam Dornan
4ffc7c5ce1 style: apply the formatting requires-python already implies (#4638) 2026-09-19 12:33:45 -04:00
zurdi
aeef54d044 fix(covers): derive cover sizes off the event loop (Greptile review)
Addresses Greptile's review of #4613:
- Write the small cover and the WebP copies in a worker thread, since
  Pillow's work now scales with an animation's frames.
- Annotate the new converter fixture and the artwork test's tmp_path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 11:20:41 +02:00
zurdi
9424347708 style(covers): trim animated cover comments (review-polish)
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 11:01:04 +02:00
zurdi
0318f078ae refactor(covers): simplify animated cover handling (simplify)
Simplify pass over the animated cover change:
- Encode animated small covers as WebP whatever the source, which drops
  the per-format GIF/APNG blending params and makes their WebP copy a
  plain file copy.
- Fold the is_animated gate into frame_durations and decode the small
  cover's frames in the same pass that reads their durations.
- Write uploaded animated artwork through the atomic write_file.
- Share test fixture constants and the animation encoder, and pin the
  per-frame pixel budget with a GIF whose canvas grows mid-animation.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 11:00:14 +02:00
zurdi
88a82a729f fix(covers): bound and harden animated cover processing (code-review)
Code-review pass over the animated cover change:
- Cap the pixels decoded across an animation (MAX_ANIMATION_PIXELS),
  counted per frame since a GIF canvas can grow mid-animation, so an
  oversized animation falls back to its first frame.
- Fall back to the first frame when a later frame fails to decode,
  instead of dropping the cover or escaping the error handlers.
- Store uploaded animated artwork as uploaded, like downloaded covers.
- Re-encode composited frames so each replaces the last (no GIF/APNG
  ghost trails), and keep GIF loop counts when converting to WebP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 10:45:29 +02:00
zurdi
b326e66db9 fix(covers): keep animated covers animated after applying them
The small cover and the WebP copies were written through PIL, which keeps
only the first frame, so an animated SteamGridDB cover showed as a still
image everywhere once applied. Resize and convert every frame with its
timing, copy WebP sources instead of re-encoding them, and keep all
frames of uploaded animated artwork.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 10:22:02 +02:00
Georges-Antoine Assi
05f445a4cf refactor(scan): ask the handler whether a rom is a folder
`directory_exists` and `Rom.full_path` already spell out the check the
scan does at its own call site, so the path is no longer rebuilt here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 07:17:51 -04:00
Georges-Antoine Assi
c28059c328 chore(scan): review-polish the title id extraction pass
Name the candidate predicate for what it checks, trim the ordering
docstring, and drop the comments the moved guards made stale.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 22:02:32 -04:00
Georges-Antoine Assi
9e940e7d10 refactor(scan): simplify the title id extraction path
Sort title id sources with the natural key the models already compute,
give the compressed suffixes one home, and let SigilService reject a
container itself rather than trusting every caller to.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 22:00:57 -04:00
Georges-Antoine Assi
cf8d79f9f6 fix(scan): apply pr-ready code-review findings
Order discs by their number so "Disc 2" precedes "Disc 10", test one
rule for containers sigil cannot read, and drop the unreachable
OSError handler around Path.is_file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 21:53:31 -04:00
nendo
3ca79a1205 fix(scan): reread title ids on every rescan and break sort ties by exact name 2026-09-17 07:36:21 +09:00
nendo
2e6acaac3c Merge remote-tracking branch 'upstream/master' into fix/sigil-cnf-serial-shapes
# Conflicts:
#	backend/tests/utils/test_m3u.py
2026-09-17 07:09:35 +09:00
nendo
d43e4e731f chore(scan): review-polish the title id ordering comment 2026-09-17 07:01:35 +09:00
nendo
f40bd69d9d refactor(scan): resolve playlists in the sigil service and keep one stop rule 2026-09-17 07:00:49 +09:00
nendo
35f799086d fix(scan): apply code-review findings to title id source ordering 2026-09-17 06:57:17 +09:00
nendo
c6170db6bc fix(scan): identify multi-disc and playlist roms by their first disc 2026-09-17 06:14:08 +09:00
zurdi
e869ecb6b6 Enforce media allowlists and walkthrough provenance in the shared upload path
A folder the scanner maps to a media category now refuses files that
category cannot hold inside resolve_upload_destination, so the chunked
flow the v2 tabs use gets the same allowlist the media routes had, and
those routes drop their own copies. commit_upload records an upload
provenance for walkthrough files that arrive without one and returns the
registered row, which the walkthrough route uses for author and title.
The refresh lock moves to Redis so uploads landing on different gunicorn
workers cannot drop each other rows. An empty body filename is rejected
instead of falling back to the header.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 16:27:38 +02: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
Georges-Antoine Assi
568aa818de refactor: tighten the library structure naming and docstrings
Rename `FirmwareTemplate.platform_path` to `firmware_dir`: it returns the
firmware folder, while the same name on `StructureTemplate` returns the platform
folder. Name the watcher's index for the segment it points at.

Fold the two reads of a raw structure key into `_raw_template`, and drop the
docstrings that only restated a one-line delegation or a signature.

Remove `footer-create-summary-default`, which no component references and whose
copy still named Structure A.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 08:53:55 -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
dd7f46b52c fix: make metadata exports and matching follow the library structure
Testing the custom library structure against a live library turned up four
defects, all of them a path being reduced to a bare file name.

Both exporters wrote a rom's `fs_name` alone, so every game a template nests
was exported as if it sat in the platform folder: ES-DE and Pegasus could not
find any of them. They now write the rom's path relative to the platform
folder, the folder the metadata files themselves live in, and copy exported
media into the matching subfolder so two identically named roms keep their own
artwork.

Merging into an existing gamelist.xml / metadata.pegasus.txt keyed entries by
file name too, so identically named roms in different folders both merged into
the first entry and produced duplicates. Entries are now keyed by path, with a
Pegasus block matched by the folder its listed files sit in.

Reading a gamelist.xml had the same collision: two roms sharing a file name
both took the metadata of whichever entry was parsed last. A rom's own path now
wins, and a bare file name stays a fallback key for the tools that write those,
dropped when two entries share it.

Default discovery surfaced hidden folders as multi-file games, unlike
structured discovery which skips them. exclude_multi_roms now owns that rule
for both.

Also validate `exclude`'s exclusion_type: an unknown value reached
`Config.__getattribute__` and returned a 500 rather than a 422.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 07:31:05 -04:00
Georges-Antoine Assi
6b01e9943e refactor: trim review-pass comments and cover LocationChip
Cut the comments that explain rather than note: the migration's four-paragraph
docstring, the upload-path and digest-SQL docstrings, and the mark-missing note
in the scan loop. Drop an em-dash from LocationChip's header per CLAUDE.md.

Reword 0126's downgrade error so it no longer embeds a SELECT, which bandit
reads as string-built SQL, and mark the dialect-selected backfill nosec B608 the
way the other migrations do.

Add the LocationChip test its HashChip sibling already had, covering the copy
going through useClipboard (the composable is what applies the secure-context
guard).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 20:17:28 -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
a73667a5ca refactor: rename the parsed template type to StructureTemplate
`LibraryStructure` named two unrelated things: the A/B enum for which of
RomM's two folder layouts a library uses, and this branch's parsed
per-platform template. Both were imported into handler/filesystem.

The parsed template is now `StructureTemplate`, with `parse_library_structure`
and `parse_platform_structures` following it to `parse_structure_template` and
`parse_platform_templates`. `LibraryStructure` again refers only to the enum.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 17:50:08 -04:00
Georges-Antoine Assi
9dcaf89890 fix: address PR review feedback on library structure and relocation
A grouping folder is no longer also a game. With `{gameDir}` and
`{category}/{gameFile}` declared together, the category folder was surfaced
as a multi-file game *and* descended into, listing its contents twice. A
folder any template descends into is now treated as a grouping level.

Relocation runs for every platform, not only those with a custom structure.
Dropping a platform's template moves every game back to the platform root,
which previously read as a library of new games and orphaned all the saves,
play history, favorites and collection membership. A library whose paths are
unchanged still costs one query and no hashing. This also removes the need
for a manual "apply relocation" toggle.

Physical games are excluded from relocation candidates: they have no file, so
they read as having disappeared from their path on every scan.

A near-miss on the terminal macro (`{gameFolder}` for `{gameDir}`) now names
the offending section instead of only reporting a missing terminal.

Documents two limits the QA pass asked about: a move that also compresses or
extracts the game changes its size and is not detected (the size pre-filter
runs before hashing), and how reverting to the default layout behaves.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 17:01:33 -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
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
8cc1e8bd15 style(gamelist): trim the media map comments to the non-obvious why
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 16:29:56 -04:00
Georges-Antoine Assi
65b2a050c1 refactor(gamelist): give the ES-DE media folder names one home
Fold the exporter's folder map and the importer's ESDE_MEDIA_MAP into a
single GAMELIST_MEDIA_DIRS, so writing, reading and skipping a media type
is one edit. This also picks up thumbnails/, which the scan exclusions were
missing, and drops the hand-appended "images" literal.

Serve the multi-file defaults pre-unioned as DEFAULT_EXCLUDED_MULTI_DIRS so
neither UI has to re-join two lists; v1 was still mapping EXCLUDED_MULTI_FILES
to DEFAULT_EXCLUDED_DIRS and rendering the media dirs as deletable.

Collapse the per-tag asset loop and the bespoke <mix> block into one table
keyed by tag, and skip fnmatch for the exclusion patterns that hold no glob
characters, now that the multi-file list is more than twice as long.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 16:19:55 -04:00
Georges-Antoine Assi
eec574b49b fix(metadata): give UniversalPlatformSlug a leaf home
Both CI failures came from one import cycle. RQ could no longer resolve
`endpoints.sockets.scan.scan_platforms`, and the e2e seed script failed the
same way, because `sigil` imports the platform slug enum, importing anything
under `handler.metadata` runs its `__init__`, that reaches `gamelist_handler`
which imports `handler.filesystem`, and `roms_handler` there imports `sigil`
back while it is still half-initialised.

The cycle predates this branch. It stayed hidden because `scan.py` reached
the enum through `utils.switch`, imported late enough that
`handler.filesystem` was already loaded; naming the adapter directly moved
that import to the top of the module and the ordering luck ran out.

So the enum moves to `utils/platform_slugs.py`, which imports nothing but
`enum`. Naming a platform no longer drags in httpx, redis and the titledb
task, and the 29 call sites point at the module that owns it rather than
picking it up from a 1000-line metadata handler that happens to re-export
it. `import adapters.services.sigil` now also works on its own, which it
did not before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 14:28:49 -04: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
8db38f3322 Merge remote-tracking branch 'origin/master' into feature/sigil-title-ids-followups
# Conflicts:
#	backend/handler/filesystem/roms_handler.py
#	backend/tests/endpoints/sockets/test_scan.py
2026-09-04 10:33:45 -04:00
Georges-Antoine Assi
9946256301 Merge branch 'master' into fix/zip-cache-readable-and-locked 2026-09-04 09:56:59 -04:00
Georges-Antoine Assi
352473d28c refactor(download): share the served-file mode and slim the zip cache
Give 0o644 a single home in utils/filesystem as SERVED_FILE_MODE, used by
both the ZIP cache and FSHandler._atomic_write. Collapse the mode repair to
one call site behind a single stat per cache hit, close the temp descriptor
unconditionally, and log the build where the namespace is already in scope.

Deduplicate the test fixtures and drive the concurrency test with a barrier
on flock instead of a sleep, so the race is guaranteed rather than timed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 09:48:03 -04:00