Commit Graph

1955 Commits

Author SHA1 Message Date
Sam Dornan
26f595d8b9 fix(hltb): match titles whose series prefix the catalogue omits
HowLongToBeat is searched with the filename, and a series prefix that one
side carries and the other does not sinks a strict similarity gate: "007:
Quantum of Solace" scores 0.838 against the catalogue's "Quantum of
Solace", just under 0.85, and a term long enough returns no results at
all. Every James Bond title on PlayStation 2 missed for one of those two
reasons.

Retry with the part after the last separator, the same recovery Moby and
ScreenScraper already make. The trigger is broader than theirs, which
only retry an empty result set: a scored-but-rejected result has to
retry too, since that is how "Quantum of Solace" fails.

Verified against the live API: all five PlayStation 2 James Bond titles
now resolve, and six subtitle-heavy titles that could plausibly match the
wrong game on a tail-only search are unaffected, because the full term
matches first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 17:01:28 -05: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
Georges-Antoine Assi
427510082d Merge pull request #4206 from sdornan/claude/normalize-region-language-tags
fix(scan): normalize region and language tags to one canonical spelling
2026-08-16 16:55:01 -04:00
Georges-Antoine Assi
a1d2cb0d4f fix(scan): keep an empty "Reg-" tag out of the region facet
A "Reg-" prefix with nothing behind it stored an empty string as a
region. It now falls through to the ordinary tags like any other
unrecognized value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 16:47:49 -04:00
Georges-Antoine Assi
9b9dba0dfe fix(scan): drop region aliases and the tag backfill migrations
Region tags now resolve only through the canonical REGIONS names and
shortcodes, so alternate spellings such as (US) or (EU) stay plain tags.
Existing rows keep whatever parse_tags wrote for them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 16:40:12 -04:00
Georges-Antoine Assi
8f3460e820 Merge pull request #4198 from XenuIsWatching/fix/scan-memory-and-listing-perf
perf(scan): cut scan memory and drop a quadratic file listing check
2026-08-16 14:22:57 -04:00
Georges-Antoine Assi
0afc1bf191 Merge pull request #4188 from sdornan/claude/single-file-rescan-perf-483f79
perf(scan): scope a rom-id scan to the selected roms
2026-08-16 13:57:51 -04:00
Georges-Antoine Assi
77d4db5209 Merge pull request #4181 from justinjd00/fix/moby-double-url-encoding
fix: remove double URL-encoding of MobyGames search terms
2026-08-16 12:34:34 -04:00
Georges-Antoine Assi
e1de724421 chore: trim comments in moby_handler
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 11:33:34 -04:00
Georges-Antoine Assi
c8c6a5d997 Merge pull request #4163 from sdornan/claude/github-issue-4159-archive-read-errors
fix(hashing): surface unreadable zip and tar archives
2026-08-16 09:02:51 -04:00
Georges-Antoine Assi
e37dfd5ce9 Merge pull request #4162 from sdornan/claude/github-issue-4157-3f916e
feat(hasheous): map famicom to the NES platform
2026-08-16 08:38:34 -04:00
Georges-Antoine Assi
d7913f4468 Merge pull request #4156 from sdornan/claude/github-issue-4128-134860
fix(export): stop miximage_v2 colliding with miximage, persist gamelist back covers
2026-08-16 08:30:28 -04:00
Sam Dornan
17b20ba423 fix(scan): canonicalize legacy collection criteria and bound migration memory
Review follow-ups on the region and language normalization.

Smart collections created by early versions store a single value under
`selected_region` / `selected_language` rather than a list, and
get_smart_collection_criteria still reads those keys. The migrations only
rewrote the list-valued ones, so a legacy collection kept filtering on "US"
against rows that had become "USA" and silently matched nothing. Both keys
are now handled, preserving each value's scalar or list shape.

The roms backfill also loaded every tagged row before writing anything, so
peak memory scaled with the library on a migration that runs at startup. It
now walks the table by id, holding one batch at a time. The collections pass
still reads in one go: that is one row per user-created collection.

Also strip the "Reg-" capture, since the separator class doesn't swallow a
following space and "[Reg- PAL]" stored " PAL" as its own facet value, and
add a test enforcing the REGION_ALIASES constraint that was only a comment.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 19:18:31 -05:00
Sam Dornan
5d565d3ae0 fix(scan): normalize region and language tags to one canonical spelling
parse_tags only canonicalized a region or language written as a shortcode.
A tag written as a name kept the filename's casing, and a "Reg-" prefixed
code outside the shortcode table was stored verbatim, so one library could
hold "USA", "usa", "Usa" and "US" as four values. Each became its own entry
in the filter dropdowns and its own bucket in the platform stats.

Both kinds now resolve through a case-insensitive lookup, with a region
alias table for the spellings the frontend's regionToEmoji already knew
about (US, EU, EUR, JP, BRA, CHN, GLOBAL) plus WR for World.

The region pass runs before the language pass but after both exact-code
checks, because Nl/NL and No/NO differ only by case: exact matching keeps
Dutch and Norwegian, and a lowercased "nl" resolves to the region.

Migrations 0108 and 0109 rewrite rows scanned before this. They also
normalize smart_collections.filter_criteria, whose saved values are
exact-matched against roms.regions, so a collection filtering on "US"
would otherwise silently match nothing. roms_facets follows through the
triggers added in 0100.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 19:01:00 -05:00
Georges-Antoine Assi
de28f574f1 Merge pull request #4146 from Spinnich/fix/archive-member-hash-lookup
fix(metadata): identify archives and folder ROMs by the right file
2026-08-15 17:19:05 -04:00
Ryan McClelland
def2d441cb fix(gamelist): drop partial results when a document is unparseable
Streaming means valid entries are consumed before the parser reaches
any damage further down the file, so a truncated or corrupt gamelist
returned whatever had been read so far. The previous full-document
parse rejected such a file outright and imported nothing.

Clear the accumulated entries when a parse error escapes both the
incremental pass and the fallback, restoring that behavior. Errors
raised while building an entry still keep what was read, as before.

Also filter the fallback path to game/folder elements so it matches the
incremental path, and hoist the lowercase filename and suffix tuple out
of the per-extension loop in exclude_single_files.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TLTDjv3niosCXZWtjKELK2
2026-08-14 12:22:28 -07:00
Ryan McClelland
28be8b7ad8 perf(gamelist): parse gamelist.xml incrementally
_parse_gamelist_xml read the whole file, ran two regex rewrites over it
and built a tree for the entire document before touching a single game.
On a platform with thousands of entries that tree dominates the scan's
memory, and it is discarded as soon as the per-game dict is built.

Stream top-level game/folder elements with iterparse instead, clearing
each once consumed. Measured on a synthetic 4.8 MB gamelist with 10,703
games, peak allocation drops from 33.3 MB to 3.4 MB.

ES-DE writes an <alternativeEmulator> sibling to <gameList>, which is
invalid multi-root XML that the incremental parser rejects, so those
files fall back to the previous strip-then-parse path. Entries are keyed
by filename, so re-reading elements already consumed before the failure
cannot corrupt the result.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TLTDjv3niosCXZWtjKELK2
2026-08-14 09:11:11 -07:00
Ryan McClelland
9da03db857 perf(scan): build filesystem ROM entries in a single pass
get_roms built a list of plain dicts for every entry, then rebuilt the
whole thing as FSRom instances and handed that to sorted(). Both lists
are alive at once, so a platform folder holding tens of thousands of
files carries two full copies plus the sorted output.

Build FSRom directly and sort in place. The nested flag is simply the
inverse of flat, so it no longer needs to be carried through an
intermediate dict.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TLTDjv3niosCXZWtjKELK2
2026-08-14 09:11:11 -07:00
Ryan McClelland
9fe43c903e perf(scan): drop quadratic file exclusion check
exclude_single_files collected every excluded name into a list, then
filtered the input against it with `f not in excluded_files`. That
membership test rescans the list once per file, so a platform folder
holding tens of thousands of loose files spends most of the call in
list scans rather than pattern matching.

Decide per file in a single pass instead. Behavior is unchanged,
including for duplicate file names.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TLTDjv3niosCXZWtjKELK2
2026-08-14 09:03:22 -07:00
Sam Dornan
b1c0dacb9f perf(scan): scope a rom-id scan to the selected roms
A scan with `roms_ids` set only narrowed which roms get metadata, not the
work around them: it still listed the platform folder, re-resolved the
platform's metadata, re-hashed every firmware file, synced the whole
platform's missing-file state twice, and walked every other rom in batches
to mark it present. Rescanning one file therefore cost time proportional to
the platform, not to the file.

Resolve a scoped scan's work from the database instead, via a new
`_scan_selected_roms` that skips all of the platform-wide reconciliation.
The gamelist cache warm-up stays, since hash matching reads from it.

`refresh_smart_collections` was likewise recomputing every smart collection
across the whole library after any scan; a scoped one now uses the targeted
`refresh_smart_collections_for_roms`.

A library scan never reaches an entry whose file is gone, since it walks the
filesystem. A database-driven one does, and scanning marks a rom present
unconditionally, so the scoped path checks the path first and marks it
missing rather than resurrecting it. That check needs `directory_exists`
alongside `file_exists`, which also derives `flat`/`nested` for the `FSRom`
a library scan gets from splitting its listing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:01:00 -05:00
Justin
8f809a10a6 fix: remove double URL-encoding of MobyGames search terms
The MobyGames handler pre-encoded search terms with urllib's quote()
before passing them to MobyGamesService.list_games(), which encodes the
query itself via yarl's with_query(). Titles containing special
characters were therefore double-encoded and never matched:

    'Sonic & Knuckles'  -> title=Sonic+%2526+Knuckles
    '... World + Bowser's Fury' -> title=...+%252B+Bowser%2527s+Fury

Pass the raw (unidecoded) term and let the service layer encode it
exactly once, matching how the ScreenScraper handler already works.
Adds regression tests for both the scan path (_search_rom) and the
manual-search path (get_matched_roms_by_name).

Same bug class as reported for ScreenScraper in #3467.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 19:05:48 +02:00
Sam Dornan
f15ec3e42d fix(hashing): surface unreadable zip and tar archives
The zip and tar readers swallowed read failures and returned an empty
iterator, which the hashing path can't tell apart from an empty archive:
it falls back to hashing the container's raw bytes, so the ROM gets
hashes that match no hash database and nothing explains why.

Raise ArchiveReadError instead, as the 7z and rar readers already do, so
the fallback is logged. Member streaming is now wrapped too, since chunks
are consumed outside the reader's error handling and a bad CRC escaped as
a raw zipfile error rather than falling back.

Fixes #4159

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-08 16:05:23 -05:00
Sam Dornan
217d52ac72 feat(hasheous): map famicom to the NES platform
Hasheous has no separate Famicom data object; its NES platform (68) holds
the NES/Famicom signature sets. Without a mapping, the scan skipped the
Hasheous lookup entirely for Famicom ROMs, since it gates on hasheous_id.

Fixes #4157

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-08 15:52:33 -05:00
Sam Dornan
eed6c8786b fix(export): stop miximage_v2 colliding with miximage, persist gamelist back covers
miximage and miximage_v2 both mapped to the assets/miximages directory and to
the <miximage> tag, so the v2 art was dropped by the existing-destination
short-circuit in _copy_asset and the XML carried a duplicate tag. Route the v2
variant to assets/miximages_v2 and the <miximage_v2> tag, matching the folder
and tag the gamelist handler already reads back.

The gamelist handler discovers back covers and fanart (ES-DE backcovers/ and
fanart/ folders, <backcover> and <fanart> tags) but never recorded a local
path for them, so the gl.get("box2d_back_path") / gl.get("fanart_path")
fallbacks in both exporters could never resolve. Record those paths alongside
the media types the handler already persists, and declare title_screen_path,
which populate_rom_specific_paths already emitted.

Fixes #4128
2026-08-08 11:44:13 -05:00
Georges-Antoine Assi
392cc9b0e2 Merge pull request #4143 from Spinnich/fix/cover-downloaded-twice
fix(resources): fetch each cover once instead of once per size
2026-08-08 12:05:48 -04:00
Georges-Antoine Assi
97b3a32148 cleanup 2026-08-08 11:23:53 -04:00
Georges-Antoine Assi
0f9d2fc53b Merge pull request #4139 from sdornan/claude/github-issue-4127-dd46eb
fix(ss): store the ScreenScraper box-2D front locally
2026-08-07 18:59:15 -04:00
Georges-Antoine Assi
30a04e088e Merge pull request #4125 from sdornan/claude/hltb-api-503-error-806ce9
fix(hltb): renew rejected HLTB sessions instead of failing the scan
2026-08-07 14:50:13 -04:00
Georges-Antoine Assi
e8993c1d4d run fmt 2026-08-07 14:37:11 -04:00
Georges-Antoine Assi
a5854b557e Merge pull request #4121 from sdornan/claude/launchbox-n64-matching-b7ce16
fix(launchbox): match ROMs during a scan the way Match ROM does
2026-08-07 11:24:23 -04:00
Spinnich
22c0216c14 fix(metadata): identify archives and folder ROMs by the right file
Since 4.9.0 a multi-file archive's RomFile carries a composite digest
streamed across every entry, with per-member digests kept alongside in
archive_members. Hasheous and Playmatch read their lookup digests
straight off that record, but both databases index a multi-file archive
by its largest internal member, so those ROMs stopped matching and fell
back to filename matching.

Add RomFile.lookup_hashes, which decides which digests a ROM database is
queried with: a CHD's embedded disc-data SHA-1, else the largest
archive member, else the file's own. Hasheous and Playmatch both read
it. ScreenScraper deliberately stays on the composite, since its
jeuInfos lookup falls back to romnom.

Playmatch also picked its file with the first one that had bytes,
unfiltered by is_top_level. iter_files is a bare os.walk with no sort
and Rom.files has no order_by, so a multi-disc folder ROM was identified
by an arbitrary file that could differ between machines scanning the
same library. Select the largest top-level file instead, as Hasheous and
ScreenScraper do, with a path tie-break for determinism. This half is
pre-existing rather than a 4.9.0 regression, but leaving it would keep
multi-disc folder ROMs failing on Playmatch.

The manual-match suggestion shares that selection, and no longer falls
back to the ROM-level composite: contributing nothing to a public index
beats contributing a hash of no single file.

Existing libraries need no re-hash; archive_members has been populated
since 4.9.0, so a rescan is enough.

Fixes #3742

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 13:09:02 +00:00
Georges-Antoine Assi
4b574ee284 refactor: share one article list across sort and launchbox matching
The sort key and the launchbox inverted-title matcher each carried their
own copy of the same 16 articles. Build both patterns from a single
ARTICLES tuple, and point the frontend's hand-synced copy at it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 08:42:14 -04:00
Georges-Antoine Assi
05dc9eab46 Merge pull request #4130 from Spinnich/fix/screenscraper-credential-errors
fix(screenscraper): report rejected credentials instead of a bare 403
2026-08-07 08:24:03 -04:00
Spinnich
d8522991e3 fix(resources): fetch each cover once instead of once per size
get_cover() called _store_cover() once for CoverSize.SMALL and once for
CoverSize.BIG with the same URL, and each call performed a complete fetch.
The small cover has no distinct source: it is the large image downloaded in
full and then resized in place, so the second request only re-retrieved bytes
already on disk. Every cover cost twice the bandwidth, doubled the load on
every provider, and on ScreenScraper spent a second request from the
account's quota, since media is served from the same authenticated api2
endpoints as metadata lookups.

_store_cover() now takes no size: it fetches once into big.png and derives
small.png from it, the way store_artwork() already did.

A missing small cover no longer triggers a fetch at all. get_cover()
downloads only when overwriting or when the large cover is absent, and
otherwise rebuilds the small one from the large one already on disk via
_derive_small_cover(). That drops the half-written pair case from one request
to none, and keeps a good large cover out of the blast radius of a download
that might fail. The derive path resolves its source through _get_cover_path,
so an uploaded big.jpg or a converted big.webp yields a matching small file
rather than assuming a .png extension.

Failure paths now clean up both destinations. Undecodable bytes are
discarded rather than left on disk, where they satisfy cover_exists() and
stop any later scan from refetching a working cover, and a discarded
chroma-key placeholder also clears a small cover left by an earlier scan.
_derive_small_cover() is the exception: it did not write those bytes, so a
large cover it cannot decode is left in place and only the partial small one
is dropped.

Fixes #4102

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 20:35:18 +00:00
Sam Dornan
94f6b16ec1 fix(launchbox): match dump filenames against the metadata store
LaunchBox lookups are exact key reads, so a filename that doesn't already
read like a LaunchBox title misses. Three gaps closed:

- No-Intro inverts leading articles ("Legend of Zelda, The - Ocarina of
  Time"), LaunchBox keeps them in front, so the de-inverted form is now
  tried against the name and alternate-name indexes as well. Measured over
  the No-Intro sets: N64 unmatched 200 -> 171, SNES 461 -> 318, Genesis
  285 -> 191, GBA 683 -> 576.
- Files.xml, a filename-to-title index the dump already ships and the
  update task already caches, was never read by any lookup. It now runs
  ahead of the name search, which is the only route to titles whose files
  are named nothing like them (MS-DOS, Amiga, Arcade). Its cache key gains
  the platform, since the same dump filename exists on several systems.
- A local LaunchBox install was only reachable by an exact filename,
  extension included, or by a stem equal to the title. A library of `.zip`
  archives could never match an install pointing at `.z64`, and a No-Intro
  stem still carries region tags. Both sides now reduce to shared forms.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:50:24 -05: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
Sam Dornan
4e149fb707 fix(hltb): redact session material from the request debug log
The debug log printed the session headers and the honeypot pair verbatim.
The token decodes to "<issued-at>::<public IP>|<user agent>|<key>|<hmac>",
so anyone pasting DEBUG logs into a bug report published their host's public
IP address. Logs are also downloadable through /api/logs.

Redact the session headers and drop the honeypot entry from the logged
payload, keeping the URL, search terms and timeout that make the line useful.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:48:59 -05:00
Sam Dornan
39d7fa0b0f fix(hltb): read the session after pacing, and pace renewals too
Addresses review feedback on concurrent scans (SCAN_WORKERS > 1), where the
handler singleton is shared across in-flight ROM lookups.

Read the session after awaiting the rate limiter rather than before, so a
request paced behind a peer's renewal uses the current session instead of the
one that was live when it queued, and bails out if the session went away.

Acquire the limiter before the /init renewal as well, so a wave of concurrent
403s can't burst past the cap that search requests respect. The endpoint
fixture fetch is left unpaced: it targets GitHub, not HLTB.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:48:59 -05:00
Sam Dornan
24d990f21a fix(hltb): renew rejected HLTB sessions instead of failing the scan
HLTB sessions are short-lived and pinned to the requesting IP address and
user agent. The handler fetched one session at the start of a scan and never
renewed it, so once HLTB rejected it every remaining lookup failed for the
rest of the scan.

Retry with a renewed session on 403, and back off and retry on 429. Report
the actual cause instead of mapping every HTTP error to "check your internet
connection", which is now used only for genuine connect and timeout errors.

Also fixes two adjacent bugs:

- The honeypot key was written into the caller's payload dict in place. That
  key rotates with the session, so a renewal would leave the dead key in the
  body alongside the new one.
- heartbeat() sent no user agent. HLTB rejects requests without one, and the
  httpx default only happens to be accepted today.

initialize() is now async so the session can be renewed from the async
request path, and uses the shared context httpx client.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:48:59 -05:00
Sam Dornan
d758c8f472 fix(ss): store the box-2D front locally so it survives cover priority
ScreenScraper's box-2D was the only media type that never got a local
file: it fed url_cover and nothing else. When any other provider won the
cover (the default, since SCAN_ARTWORK_PRIORITY puts ss fourth), the box
front was recorded as a URL and never downloaded, leaving it unreachable
from the UI. Enabling box2d_back/box2d_side could only be made to look
right by forcing ss to the top of scan.priority.cover.

box-2D now records a box2d_path when box2d is listed in scan.media, like
every sibling media type. The Artwork subtab lists the box front, and
the interactive 3D box takes its front face from that scan (falling back
to the rom cover), so all three faces come from the same source and the
3D box no longer depends on cover priority.

Fixes #4127

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:38:35 -05:00
Georges-Antoine Assi
960e18df77 Merge pull request #4131 from sdornan/claude/romm-file-copy-errors-3667f5
fix(media): stop recording paths for media that never landed
2026-08-06 10:19:57 -04:00
Sam Dornan
63aa82566e refactor(hashing): call CHD probe inline instead of via a thread
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 21:21:21 -05:00
Sam Dornan
984c40c158 fix(media): clear a recorded media path that has no URL to fetch from
A *_path with no matching *_url can never be fetched, so it must not
survive when the file it names is missing. No provider produces that
state today (each gates the path on the URL), but store_metadata_media
now guarantees every path it leaves behind points at a real file.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 15:07:16 -05:00
Sam Dornan
656c5d7d23 fix(media): stop recording paths for media that never landed
Metadata providers record where each media file should live at match time,
and the path was persisted whether or not the download produced a file. A
non-200 response, an unexpected content type, a transport error, or a
discarded ScreenScraper chroma-key placeholder all leave nothing on disk,
so the ROM kept pointing at a file that was never there.

Local gamelist/Pegasus exports then warned once per ROM per phantom asset
and left an empty assets/<subdir>/ behind, and the frontend built box-face
URLs that 404.

store_media_file now reports whether the file is on disk afterwards, and
store_metadata_media clears the *_path entry for anything that didn't land
while keeping the *_url so a later scan can retry. Both exporters skip a
missing source quietly instead of warning, and no longer create the
destination directory before knowing the source exists.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 14:54:45 -05:00
Sam Dornan
a3d6fef4ac Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-08-05 14:05:57 -05:00
Sam Dornan
dc933fe4b5 fix(hashing): extract CHD SHA-1 for folder-based ROMs
The folder branch of get_rom_files probed for a CHD header at
<walked dir>/<rom folder name> instead of the file being walked, so the
path never existed and chd_sha1_hash came out empty for every file of
every per-game-folder ROM, single-disc included.

This also degraded metadata matching, since Hasheous lookups fall back
to the container's MD5/SHA-1/CRC when the disc-data SHA-1 is missing,
and those match nothing for a CHD.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 13:59:46 -05:00
Spinnich
04bd7d9d72 fix(screenscraper): report rejected credentials instead of a bare 403
ScreenScraper answers a bad credential set with HTTP 403 and a body that
says so, but the login-error check sat after raise_for_status(), so it
could never match the case it was written for. The scan logged
"403, message='Forbidden'", carried on, and saved every ROM without
ScreenScraper metadata, with nothing anywhere naming the credentials.

The body is now read before the status is raised, and a 403 raises a
ScreenScraperCredentialsError that says which of the two credential sets
was refused. The account endpoint is the only one that checks the account
password, so a refusal there names SCREENSCRAPER_USER and
SCREENSCRAPER_PASSWORD, and a refusal from a scraping endpoint can only
be about the RomM developer credentials. That message does not name their
variables: they are only semi-protected, and nothing should send an end
user looking for them. ScreenScraper's own wording is carried through
under both, because it cannot attribute the fault by itself: with a bad
developer id, ssuserInfos.php still blames the account. That wording
reaches the caller as well as the log, and the credentials travel in the
query string, so it is masked with the regex the log formatter already
uses.

The refusal surfaces as a 403, matching the blacklisted-version case:
both mean ScreenScraper refused RomM itself and both need an operator
change, unlike the transient failures that map to 503. Never a 401,
which the frontend reads as an expired session and acts on by returning
the user to the login page.

A refusal trips a breaker like the daily quota does: it is reported once
and the remaining requests short-circuit rather than spending a round
trip per ROM to be told the same thing. The scan-path lookups treat it
like an exhausted quota, so a scan degrades to the other providers
instead of failing outright. Manual searches still surface the error.

The account check reports a refusal but never arms that breaker.
ScreenScraper refuses a developer id it accepted a minute earlier while
the scraping endpoints keep answering, so leaving the breaker armed cost
a working scan all of its ScreenScraper metadata. Only the requests a
scan actually needs can take the provider out.

prime_account_limits() now warns whether the lookup raised or was
swallowed into an empty response, which is what left a scan with no
limits, no quota readout and no explanation.

The HTTP 401 message gains the half of ScreenScraper's error table it
was missing: the API is closed to non-members and inactive members, with
server saturation given as the cause.

Both attempts had diverging copies of the status ladder, so they now
share one mapping.

Fixes #4122

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 18:57:54 +00:00
Georges-Antoine Assi
906a1c0533 Merge pull request #4086 from bikeborb/fix/csrf-anonymous-stale-token
fix(auth): accept a stale user-bound CSRF token on anonymous requests
2026-08-04 08:31:34 -04:00
Georges-Antoine Assi
d67dde2226 Merge pull request #4078 from Spinnich/fix/metadata-sort-perf
perf(roms): sort metadata fields on the indexed roms column
2026-08-04 08:25:30 -04:00
Spinnich
28739f93df chore(roms): trim the comments on the metadata sort columns
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 12:14:08 +00:00