Commit Graph

1890 Commits

Author SHA1 Message Date
Georges-Antoine Assi
eba61d9d3a Merge remote-tracking branch 'origin/master' into fix/permission-gaps-5.1.0
# Conflicts:
#	backend/tests/tasks/test_cleanup_orphaned_resources.py
2026-07-30 18:22:50 -04:00
Georges-Antoine Assi
fee2724a0e Merge pull request #3989 from Spinnich/feat/screenscraper-quota-awareness
feat(screenscraper): pace and report scans against the account's reported limits
2026-07-30 17:52:10 -04:00
Georges-Antoine Assi
a55d50998e refactor(screenscraper): move the scan reporting into ss_handler
Priming the account, the quota lines and the end-of-scan skip list are
ScreenScraper's own bookkeeping, so they move out of the scan socket and
behind begin_scan(), log_quota() and log_scan_summary(). The scan keeps
only the decision it owns: whether this scan uses ScreenScraper at all.

The quota-line bookkeeping joins the skipped ROMs in a _ScanState
instance, so the tracking that resets together lives together and needs
no global statement.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 17:43:32 -04:00
Georges-Antoine Assi
440cc6fa2d docs(roms): drop two redundant comments
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 14:58:42 -04:00
Spinnich
fdb000576a perf(roms): stop the Missing tab scanning the whole library
Settings -> Library Management -> Missing made three whole-library passes
per request, two of which produced data the page never renders, and none
of which could be cached because "missing" counts as a filter.

- The tab now opts out of the char index, the filter values and the
  ordered id index, so the endpoint serves its total from a plain COUNT.
- `missing_from_fs` gets a composite index with `name_sort_key`, and the
  filter compiles to an equality: MariaDB does not treat `IS NOT FALSE`
  as indexable, so the index would otherwise only ever be scanned end to
  end. The column is NOT NULL, so both forms match the same rows.
- The filter-value list is keyed on the scope (search / platform /
  collection) alone. It is built from a query that never applies the
  row-level filters, so a filtered request now answers with, and warms,
  the same whole-library entry an unfiltered one does.

Fixes #3992

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-30 12:13:03 +00:00
Georges-Antoine Assi
426be64dc7 fix(security): close three permission gaps from the 5.1.0 audit
Restrict ROM file deletion to the ROMS/DELETE grant. The new
DELETE /roms/{rom_id}/files/{file_id} route gated on ROMS_WRITE alone and,
unlike its manual/soundtrack/screenshot siblings, carried no category guard,
so a group holding write-but-not-delete could remove game files from disk
while whole-ROM deletion still required ROMS/DELETE.

Gate mutating streaming routes on ROMS_USER_WRITE instead of ROMS_READ,
matching the play-session routes. ROMS_USER_WRITE is always-on for
authenticated users, but absent from READ_SCOPES, which is all KIOSK_MODE
grants an anonymous visitor. Kiosk visitors all share user_id=-1, so session
ownership could not separate them and any visitor could claim sessions and
overwrite another's save states.

Restore the ENABLE_SCHEDULED_CLEANUP_ORPHANED_RESOURCES gate on the cleanup
task's cron_string. It was dropped in 06cafd4b1, whose message refers to
update_switch_titledb, leaving the documented opt-out inert and scheduling a
destructive task nightly. That commit also broke two of the task's own tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-29 18:28:04 -04:00
Spinnich
c7284f02d2 Merge remote-tracking branch 'upstream/master' into feat/screenscraper-quota-awareness
# Conflicts:
#	backend/endpoints/sockets/scan.py
2026-07-29 14:01:06 +00:00
Spinnich
c2786429fd fix(screenscraper): address review feedback on quota awareness
Four points from the PR review:

- Leave the process-global ScreenScraper state alone when a scan does not use
  ScreenScraper. DEV_MODE runs scans in-process, so overlapping scans could
  otherwise clear each other's learned limits and skipped ROMs.
- Return pacing to the defaults when the per-scan state resets. Priming re-reads
  the account moments later; should that fail, the conservative default is safe
  for whatever account the credentials now name, whereas the previous scan's
  allowance may be more than this one is entitled to.
- Stop a rate-limited ROM from trying the next lookup. A refusal that survives
  the retry now propagates out of the handler and is caught once per ROM in
  fetch_ss_rom, instead of being swallowed per call site and sending the caller
  on to spend another retried request against a budget that is already gone.
  _is_daily_quota_error excludes the rate-limit 429 so the two stay distinct.
- Hand the request slot back before inspecting and re-encoding a cover, so
  local image work no longer holds a ScreenScraper thread.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 13:55:19 +00:00
Georges-Antoine Assi
ff8d4d0d5d Merge pull request #3986 from rommapp/fix/launchbox-cloud-empty-store
fix(launchbox): stop the cloud provider from silently matching nothing
2026-07-28 23:09:10 -04:00
Spinnich
e1225c8a9c fix(screenscraper): don't repeat an unchanged quota line
The last platform's quota readout and the end-of-scan summary both call
_log_ss_quota, so a completed scan printed the same numbers twice in a row.
Skip a line identical to the previous one, resetting at the start of each scan
so a new run always reports.
2026-07-29 01:30:18 +00:00
Georges-Antoine Assi
52940ea3d4 fix(launchbox): stop the cloud provider from silently matching nothing
LaunchBox cloud lookups read from a Redis store that only the metadata
update task fills, but nothing surfaced when that store was empty. The
provider reported healthy, every search returned zero results, and the
logs said nothing.

- heartbeat now reports unhealthy until the store is populated, and an
  empty store logs what to set to fix it
- the update task can be run manually whenever LAUNCHBOX_API_ENABLED is
  on, instead of also requiring the scheduled-update flag
- the ~600k entry dump was buffered into a single pipeline, peaking at
  1.7GB of RSS and writing nothing at all if the job was killed part way
  through. Writes now go out in batches and parsed elements are dropped
  as they are consumed, which caps the run at ~260MB. The task also gets
  its own timeout, since the default 5 minutes does not cover a 100MB
  download plus a 500MB parse
- alternate name lookups ignored the platform, so "Super Mario World" on
  PlayStation matched Super Mario Bros.
- Coleco ADAM was spelled wrong, and Famicom / Super Famicom pointed at
  platform names LaunchBox does not use

Fixes #3981

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 19:55:16 -04:00
Georges-Antoine Assi
ae46dc64c2 fix(tasks): make the upload tmp cleanup importable by the RQ worker
Importing the task module first, as the worker does when it resolves the job,
pulled endpoints.roms in and closed an import cycle through decorators.database.
RQ hides the ImportError behind "Invalid attribute name: run", so the cleanup
never ran and orphaned chunked-upload directories piled up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 18:41:51 -04:00
Ryan McClelland
903df17f6e fix(scan): detect scans on every queue and entry point
Scan job discovery only looked at the high priority queue and only
recognised scan_platforms, so two kinds of in-flight scan went unseen.

Watcher scans are delayed through the scheduler and land in the low
priority queue, so the concurrency guard let a manual scan start
alongside one and the stop handler left it queued to run afterwards.

The scheduled rescan enqueues its own task and calls scan_platforms in
process, so the worker reports the task's name. That made stopping it a
silent no-op: with no running job matched, the stop flag it polls was
never set.

Discovery now spans both queues plus the scheduler and matches either
function name. The scheduler registry also holds the standing cron entry
for the scheduled rescan, which is a schedule rather than a pending
scan, so only delayed scan_platforms jobs count as queued.

Clearing the stop flag at scan start is now scoped to the scan that owns
it, so a scan starting next to one that has not yet polled the flag
cannot drop a stop request meant for it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-28 12:47:31 -07:00
Spinnich
8b51f37fd4 feat(screenscraper): read the account limits before a scan starts
The limits ride along on every response, so learning them from the first
scrape response meant the opening requests of a scan ran at the default one
thread and 50 requests per minute, and the quota only became visible once a
platform finished.

ssuserInfos.php reports the same ssuser block up front. Unlike the scraping
endpoints it does not consume the daily quota (measured: two reads 90s apart
moved requeststoday by 0), so a scan can ask once at startup and pace itself
correctly from the first request, logging the quota and the SCAN_WORKERS
advisory before the first ROM is touched.

Best effort: a refused or unreachable lookup logs a warning and the scan
carries on.
2026-07-28 19:01:04 +00:00
Spinnich
5fb27a55f9 feat(screenscraper): make scanning aware of the account's reported limits
ScreenScraper returns the account's allowances on every response, but only
maxthreads was read. Use the rest:

- Pace requests against the reported maxrequestspermin (falling back to the
  documented threads x 50), so fast lookups can no longer overrun the
  per-minute budget without ever exceeding the thread cap.
- Report the remaining daily and unrecognized-ROM quotas after each platform
  and at the end of a scan, and warn once when either drops below 10%.
- Hint once per scan when SCAN_WORKERS is below the thread allowance (scans
  slower than the account allows) or above it (extra workers just queue).
- Raise a distinct error when a request is refused twice for exceeding the
  rate, so the ROM is reported as skipped in the scan summary instead of being
  saved with no ScreenScraper data.
- Route ScreenScraper media downloads (covers, screenshots, manuals, mixed
  media) through the same limiters, since they are api2 endpoints that count
  against the same allowances, and derive their timeout from the account's
  advertised download speed.

Fixes #3978

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-28 17:09:52 +00:00
Ryan McClelland
99e214a8b4 fix(scan): refuse concurrent scans and stop queued ones
`scan_handler` enqueued a scan on every request without checking whether
one was already running. A client that lost the progress socket, which
happens routinely on mobile when the tab is backgrounded, has no way to
tell a scan is still in flight, so pressing scan again looks reasonable
and silently queues a second full library scan behind the first. Three
scans of the same library ran back to back on a real instance this way.

Reject the request instead, reusing the `scan:done_ko` channel that
`reject_unauthorized_scan` already uses to report a refused scan.

`stop_scan_handler` only ever cancelled the running job, so the queued
duplicates it left behind started as soon as it stopped. It now cancels
queued scans as well.

Its first lookup loop was also dead: it searched `high_prio_queue` for a
job named `scan_platform` with `is_started` set, but RQ records the name
as `endpoints.sockets.scan.scan_platforms`, and a started job is no
longer in the queue. The second loop hardcoded the full path, which is
what the first one drifted away from, so both lookups now derive the
name from the function object and are shared with the new guard.

Finally, clear the stop flag when a scan starts. It is only cleared by
the scan that observes it, so a stop requested against a scan that ended
first would leave the flag set and abort the next scan before it began.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 17:53:51 -07:00
Georges-Antoine Assi
74d1d1ad9e Merge pull request #3966 from rommapp/fix/fpkgi-multi-file-entries
Serve each PKG file as its own FPKGi entry
2026-07-27 18:07:03 -04:00
Ryan McClelland
90d1c72256 feat(tasks): allow orphaned resource cleanup to run on a schedule
Orphaned covers and screenshots left behind by deleted ROMs accumulate
indefinitely, because the only way to reclaim them is to trigger the
cleanup task by hand. On a long-lived instance the resources directory
grows without bound, which is a problem when it shares a filesystem with
the database.

Move the task to `tasks/scheduled/` and turn it into a `PeriodicTask`
with an opt-in cron schedule, defaulting to 5:00 AM so it runs after the
nightly scan and metadata tasks have settled.

`enabled` stays `True` rather than tracking the new env var, because the
run-task endpoint requires both `enabled` and `manual_run`. Gating it
would have silently removed the ability to run the cleanup by hand,
which is how it works today. The cron string is what is opt-in, and
`init()` unschedules when it is unset.

Add the new flag to the init script's scheduler condition, so enabling
only this schedule still starts `rqscheduler`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 13:53:30 -07:00
Georges-Antoine Assi
a93799720e Skip missing packages and reuse real title ids in the FPKGi feed
Files marked missing_from_fs were still advertised, so FPKGi listed a
package whose download URL no longer resolves.

Title ids now come from a CUSA/PPSA id in the rom or package file names
when present, falling back to the generated RomM id. It is resolved once
per rom so a base game and its updates/DLC stay grouped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 08:20:49 -04:00
Georges-Antoine Assi
f896c2cc8c List each PKG file as its own FPKGi entry
FPKGi installs one package per entry, but the feed served a single entry
per rom pointing at the rom download URL, which zips multi-file roms.

Each .pkg file now gets its own entry with its own size and download URL,
named after its category (or file name) when a rom holds several packages.
Adds an optional content_type filter so FPKGi's per-category content URLs
can each point at RomM.

Fixes #3962

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 07:58:52 -04:00
Georges-Antoine Assi
78c8550883 cleanup 2026-07-26 16:47:00 -04:00
Georges-Antoine Assi
9b0f281df1 Bind note update/delete to the rom in the path
update_rom_note and delete_rom_note selected on note_id and user_id only,
so the rom resolved from the path never constrained which note was
touched. Pairing a note id with any other rom id in the path reached that
note regardless.

Both handlers now filter on rom_id as well, and the endpoints pass the
rom they resolved.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 16:42:58 -04:00
Georges-Antoine Assi
b1ac647322 Enforce hidden-rom visibility on rom child routes
The screenshot, soundtrack, manual and note routes looked up the rom by
path id but never ran the visibility gate that the core rom routes and
roms/files.py already apply, so a hidden rom stayed reachable through its
child resources.

Add assert_rom_visible() after each lookup. update_rom_note and
delete_rom_note took {id} in the path without resolving it at all, so
they now load the rom first.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 16:33:38 -04:00
Georges-Antoine Assi
96833892ce security: enforce asset upload limits before spooling, cover screenshots
Addresses the Greptile review on #3952.

- Reject oversized asset uploads from Content-Length in middleware, before
  FastAPI parses and spools the multipart body to temporary storage. The
  handler-level check stays as a backstop for chunked requests.
- Apply the limit to screenshot fields on the save, state and standalone
  screenshot endpoints, not just the primary file.
- Clamp the autocleanup limit to at least 1 so a non-positive value cannot
  wipe every save in a slot.
- Document the new settings in env.template.

Rename MAX_SAVE_UPLOAD_SIZE_BYTES to MAX_ASSET_UPLOAD_SIZE_BYTES now that it
covers states and screenshots too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 09:24:42 -04:00
Sunil
49e16cd2c4 security: harden CORS, session cookies, filename sanitization, and upload limits
- Fix CORS misconfiguration: replace allow_origins=[*] with configurable
  ROMM_CORS_ALLOWED_ORIGINS env var to prevent cross-origin session hijacking
- Make session and CSRF cookie Secure flag configurable via
  ROMM_SESSION_SECURE_COOKIE for deployments behind TLS-terminating proxies
- Harden sanitize_filename() with os.path.basename() to strip directory
  traversal components and reject . / .. entries
- Add upload size limit (MAX_SAVE_UPLOAD_SIZE_BYTES, default 512MiB) to
  saves and states endpoints to prevent denial of service
- Cap autocleanup_limit parameter (MAX_AUTOCLEANUP_LIMIT, default 100) to
  prevent unbounded resource accumulation
2026-07-26 01:32:59 +05:30
Georges-Antoine Assi
93a128965b Merge pull request #3936 from Spinnich/fix/rom-detail-smart-collections
fix(roms): list the smart collections a ROM belongs to on its detail view
2026-07-24 21:38:13 -04:00
Spinnich
c6c80d8239 perf(roms): resolve smart-collection membership in SQL, not Python
The detail response listed a ROM's smart collections by loading every
own/public smart collection and scanning its cached rom_ids list in
Python. rom_ids grows with library size, so this got heavier on large
libraries on every detail load.

Push containment + visibility into the query via the existing cross-DB
json_array_contains_value helper (JSON_CONTAINS on MariaDB/MySQL, @>/?
on Postgres), returning only the matching rows with id/name/is_public.
The schema mapper no longer filters, so smart_for_user becomes the plain
from_smart_collections mapping. Behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 14:57:43 +00:00
Spinnich
95d5cbfcdf fix(roms): list smart collections a rom belongs to
The ROM detail response only filled `user_collections` from a rom's
standard collections (the collections_roms join), so smart collections
were silently omitted from the detail overview's Collections row.

Add smart-collection membership to the response: `UserCollectionSchema`
gains an `is_smart` flag and a `smart_for_user` builder that keeps the
smart collections whose cached rom_ids include the rom (respecting own /
public visibility), and `DetailedRomSchema` appends them alongside the
standard ones. The v2 overview renders them with the smart kind badge and
routes them to the smart-collection view.

Fixes #3934

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 14:21:35 +00:00
Georges-Antoine Assi
5744e2e518 Merge pull request #3896 from tmgast/feature/music-playlists
Add music favorites and playlists API
2026-07-23 15:14:54 -04:00
Georges-Antoine Assi
1bdd77661e cleanup 2026-07-23 14:44:56 -04:00
Georges-Antoine Assi
c99154a5d0 Merge pull request #3903 from rommapp/fix/emit-restored-roms-during-platform-scan
fix(scan): emit a client update for ROMs that are no longer missing
2026-07-23 12:48:24 -04:00
Georges-Antoine Assi
75b10591ae refactor(music): extract the track cover url fallback
Pull the cover priority (embedded track cover, then the game's cover art)
out of from_row into a named helper on the schema, and cover the no-art
case that the endpoint tests didn't reach.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 12:05:21 -04:00
Georges-Antoine Assi
a84ad2289d refactor(music): key playlists and favorites on rom_file_id
Rescans reconcile rom_files in place since #3900, so file ids survive a
rescan and no longer need routing around. Playlist and favorite entries
reference rom_file_id directly instead of (rom_id, md5_hash).

This drops the machinery the hash key required: soundtrack audio is no
longer force-hashed during scans (which overrode NON_HASHABLE_PLATFORMS
and SKIP_HASH_CALCULATION), soundtrack uploads no longer hash on write,
adding an unhashed track no longer returns 400, and the min(file id)
subquery that collapsed identical copies within a rom is gone. Two files
with the same content are now two independently addressable tracks.

A file that leaves the library takes its entries with it via the FK
cascade, rather than leaving a dangling entry that resurrects if the
content comes back.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 10:58:53 -04:00
Georges-Antoine Assi
8c5e3d8eae Merge branch 'master' into feature/music-playlists 2026-07-23 10:48:53 -04:00
Georges-Antoine Assi
d9050eb4cc fix(scan): unlink soundtrack covers orphaned by dropped track metadata
A file that stopped carrying audio tags, or vanished from disk, had its
track_meta row dropped (directly or by cascade), leaving its persisted
cover on disk with nothing pointing at it.

sync_rom_files now reports those cover paths so the scan unlinks them,
keeping filesystem work out of the database handler.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 09:44:12 -04:00
Georges-Antoine Assi
71c04f186b fix(scan): emit a client update for ROMs that are no longer missing
A platform scan already clears `missing_from_fs` for an entry whose file
came back under the same name, but the ROM is skipped by `should_scan_rom`
so nothing emits `scan:scanning_rom` for it. An open gallery keeps showing
the stale "missing" badge until a refetch, which reads as the platform scan
ignoring missing games (a single-game scan does emit, and looks fixed).

Snapshot the flagged ids before the pre-loop sync clears them, then emit for
the restored entries after `bulk_mark_present`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 09:40:17 -04:00
Georges-Antoine Assi
83ad2b3132 fix(scan): reconcile rom_files in place instead of purging them
Rescans deleted and re-inserted every rom_files row, so file ids churned
on each scan and anything keyed on them (track metadata, persisted
soundtrack covers) was orphaned.

Rows are now matched by path first, then by content hash so a file
renamed or moved inside the ROM keeps its id, mirroring the ROM-level
reassociation. Only changed columns are written, vanished files are
deleted, and archive_members is carried over (the hand-written copy
dropped it).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 08:54:50 -04:00
nendo
70e583b9a0 Add music favorites and playlists API
Spotify-style library features for soundtrack tracks: per-user favorites
(liked songs) and user-owned playlists with manual ordering and optional
public read-only sharing.

Track references are stored as (rom_id, md5_hash) rather than rom_file_id:
scans purge and re-insert rom_files rows, so file ids churn while rom ids
and content hashes are stable. Entries survive rescans and renames, and
resolve to the current file at query time; entries whose content is gone
are omitted from listings until the file returns.

To make the content hash reliably present, soundtrack audio files are now
always hashed individually during scans (including NON_HASHABLE_PLATFORMS
and SKIP_HASH_CALCULATION, whose file-size concerns don't apply to audio),
and soundtrack uploads compute crc/md5/sha1 on write. Existing libraries
backfill via a HASHES scan; adding an unhashed track returns 400.

New playlists.read/playlists.write scopes are wired through the granular
permission system (PermEntity.PLAYLISTS); the migration mirrors every
group's collections grants onto the playlists entity so existing groups
keep working without admin intervention.

Endpoints under /api/music: favorites GET/POST/DELETE, is_favorite and
md5_hash on track rows, playlists CRUD, playlist tracks GET/POST/DELETE
and PUT /tracks/order.
2026-07-23 15:32:32 +09:00
Georges-Antoine Assi
55b3b45981 fix(roms): return 404 for single-file downloads missing on disk
In DEV_MODE the content endpoints serve a single-file ROM straight through
FileResponse, which raises a RuntimeError at send time when the file no
longer exists on disk (e.g. a renamed or moved ROM whose old entry is now
missing). Check the path first and raise a clean 404 instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 08:33:56 -04:00
Georges-Antoine Assi
b7ff92e792 more cleanup 2026-07-21 08:29:38 -04:00
Georges-Antoine Assi
7e8be36ea6 cleanup 2026-07-21 08:09:40 -04:00
Georges-Antoine Assi
d66a3f90c2 fix(scan): require CRC, MD5, and SHA1 to all match for reassociation
The reassociation lookup OR'd the individual hashes across the Rom and its
RomFiles, so a lone CRC32 collision (or one shared child-file hash) could
move an unrelated missing entry onto the scanned file, attaching the wrong
collections, notes, and assets. Require all three of CRC, MD5, and SHA1 to
match on the ROM row instead; any missing hash yields no match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 07:58:26 -04:00
Georges-Antoine Assi
6ec3820cf6 feat(scan): reassociate renamed/moved ROMs with missing entries by hash
When a ROM file is renamed or moved, the scan matched files to DB rows
solely by (platform_id, fs_name), so the old row was flagged missing and
the renamed file became a brand-new entry, orphaning all user data
(collections, notes, per-user status, uploaded saves/states/screenshots).

Now, when a scanned file matches no existing fs_name, the scan hashes it
first and looks for an existing missing_from_fs entry on the same platform
with a matching hash. On a match it moves that entry onto the new file and
clears its missing state, preserving user data linked by rom_id, instead
of inserting a duplicate. Empty hashes never match, so non-hashable
platforms and SKIP_HASH_CALCULATION fall back to creating a new entry.

File hashing is hoisted so it runs once per new file and is reused for
both the reassociation probe and the downstream scan.

Fixes #3618

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 22:28:34 -04:00
Georges-Antoine Assi
0a262ebf8d Merge pull request #3855 from Spinnich/feat/platform-descriptions
feat(platforms): add editable platform descriptions
2026-07-20 19:16:52 -04:00
Georges-Antoine Assi
31c19f754e Merge pull request #3854 from rommapp/feat/scan-settings-v2-ui
feat: editable v2 UI for scan settings
2026-07-20 18:58:15 -04:00
Spinnich
82caaf87a9 fix(platforms): address review feedback on PR #3855
Bound the user-authored fields. `description` (TEXT) and `custom_name`
(VARCHAR(400)) had no length constraint, so an oversized value reached the
database and surfaced as an unhandled DataError, turning a bad request into
a 500. Both are now validated against the column limits, which are defined
next to the columns so the bounds can't drift from the schema. The
`custom_name` case predates this branch but shares the line of code.

Make platform updates a true partial update. The shared API service took a
whole Platform object and sent every field, so the v1 rename drawer replayed
whatever description it happened to be holding; if another client had changed
the description in the meantime, renaming silently reverted it. The service
now takes explicit optional fields, so omitting one means "leave it alone"
rather than "write back my cached copy".

Watch the two form fields independently. Re-seeding both whenever either
canonical value changed meant a socket update touching only the name threw
away an unsaved description edit, and vice versa.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 20:01:05 +00:00
Spinnich
98e8ae7599 feat(platforms): add editable platform descriptions
Custom platforms could only be distinguished by name, which is often not
enough context (e.g. a "Sega - Genesis/Mega Drive (Unofficial)" folder
holding aftermarket and unlicensed dumps). Platforms now carry an
optional free-text description, mirroring collections.

The column is nullable and defaults to "", matching custom_name, so a
rescan (which merges a freshly scanned Platform over the existing row)
leaves it untouched. update_platform patches only the fields sent, so an
omitted description is preserved and an empty string clears it.

Surfaced in the v2 UI only: the Settings tab name form now covers both
custom_name and description, and PlatformHead renders the description as
a chip alongside the metadata chips. v1 is frozen and gets no new UI, but
round-trips the field unchanged through the shared API service.

Closes #3402

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 19:00:30 +00:00
Georges-Antoine Assi
191cd1f24c feat(config): editable v2 UI for scan settings
Expose the scan.* section of config.yml (metadata & artwork priority,
per-field artwork overrides, region priority, language priority, media
types, gamelist and pegasus export) in an editable v2 Settings page.

Backend:
- Add PUT /api/config/scan (platforms.write) with a validated
  ScanSettingsPayload and ConfigManager.update_scan_settings().
- Expose GAMELIST_AUTO_EXPORT_ON_SCAN and PEGASUS_AUTO_EXPORT_ON_SCAN
  in ConfigResponse / GET /api/config.
- Preserve the streaming section on runtime config writes (previously
  dropped on every write).

Frontend:
- New Settings/ScanSettings.vue page + ScanPriorityList.vue reorderable
  list (drag + up/down for keyboard/gamepad); region/language use
  RComboboxField.
- Wire the scan-settings route, permissions, and sidebar entry.
- Regenerate OpenAPI types; add all new strings to every locale.

Closes #3849

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 11:24:31 -04:00
Georges-Antoine Assi
ebc0046a1b Merge pull request #3853 from rommapp/fix/hidden-rom-authorization-bypass
fix: enforce hidden-ROM/platform visibility on asset download and streaming endpoints
2026-07-20 11:17:02 -04:00
Georges-Antoine Assi
c9a8ceedd7 fix: enforce hidden-ROM/platform visibility on asset download and streaming endpoints
Several endpoints authorized cross-user access by the is_public flag (or
by scope alone for streaming) without re-checking whether the parent ROM
or platform is hidden from the caller. A user blocked from a ROM/platform
could still download a public save/state/screenshot attached to it, or
claim a streaming session for it, by supplying the asset/ROM id directly.

Route all four through the existing assert_rom_visible() 404-masking
helper, right after loading the record and before any file access or
broker launch, matching the ROM detail/content endpoints.

- saves.py / states.py / screenshots.py download_* : public sharing no
  longer overrides the hidden-resource boundary.
- streaming.py claim_session : hidden ROM/platform can no longer be
  launched via its id; broker is never contacted.

Regression tests cover hidden-ROM and hidden-platform cascade for each
endpoint, plus a positive control that public sharing still works when
the ROM is visible.

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