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>
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>
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>
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>
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>
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>
failed_items was just the length of failed_ids. Remove the redundant
counter from the delete endpoints (roms + firmware) and the response
type; callers that need the count derive it from failed_ids.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The bulk delete endpoint deletes per-ROM and can partially fail, but the
v2 dialog pruned every requested ROM from the selection and gallery. A
ROM that failed to delete stayed in the library yet lost its selected
state, so the user couldn't retry the failed subset.
Return the failed IDs from the delete endpoints (roms + firmware, both
via BulkOperationResponse) and, on the client, only prune the ROMs that
were actually removed. Failed ROMs stay selected and visible for retry;
the single-ROM route only navigates away when its ROM was deleted.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Centralize the cache-hit-or-build-then-fallback flow into
resolve_cached_zip(), collapsing three near-identical endpoint
blocks; add ZipFileEntry.from_rom_file() factory.
- Use get_ttl_hours() (now size-based) in cleanup_stale_zips instead
of inlining the tier decision.
- Drop on-demand LRU eviction and the 2x space guard; a full disk now
falls back to mod_zip streaming via the existing build try/except.
- Replace the per-request importlib.reload(zipfile) with a one-time,
thread-safe shim that fixes zipfile_inflate64's _get_compressor
signature without a global module reload.
- Simplify get_cache_key by folding the empty-entries case into the
normal path (non-empty keys unchanged).
Generated-By: PostHog Code
Task-Id: e68b880f-34d8-4bf6-8cd0-886ef2caecb4
The home rails ("recently added" / "continue playing") request 15 cards
but the endpoint always computed rom_id_index, the complete ordered list
of every matching rom id that backs gallery virtual scroll. On large
libraries this ran a full-table scan and shipped hundreds of KB of ids
to render 15 cards.
Add a with_rom_id_index query param (defaults to true, mirroring the
existing with_char_index / with_filter_values flags). When false, skip
building the index and serve the page directly via offset/limit off the
sort index, with a lightweight count for total. The home rail fetches
pass false.
Fixes#3770
Generated-By: PostHog Code
Task-Id: 45dbad45-bd7c-4cf3-8e8f-105f174f4386
The v2 gallery per-card endpoint reused get_rom, which runs the full
detail eager-load (saves, states, screenshots, collections) that
SimpleRomSchema never serializes, making cards slow to hydrate.
Add get_rom_simple backed by a with_simple_details decorator that loads
only what SimpleRomSchema needs: platform, metadatum, rom_users, files,
sibling_roms (+ their rom_users), notes, and the deferred file-count
columns.
Fixes#3771
Generated-By: PostHog Code
Task-Id: 9233f519-079f-4990-8b48-9d12c81440b4
- Add DELETE /roms/{rom_id}/files/{file_id} endpoint to files.py
- Add deleteRomFile API function to frontend ROM service
- Add delete button (guarded by rom.delete permission) to FilesTab selection toolbar
- Show confirmation dialog before deleting; redirect to gallery when all files are removed
- Add i18n keys for delete confirmation and feedback to all 18 locale files
- Add backend tests for the new delete endpoint (success, wrong-rom 404, unknown-file 404, missing-disk-file tolerance, viewer 403)
Closes#3752
Co-authored-by: zurdi15 <34356590+zurdi15@users.noreply.github.com>
Serving any .pdf/.md file inline by extension also flipped game/extra files
from downloads to inline. Gate the document check on RomFileCategory.MANUAL so
only manuals render inline; other files keep the attachment behavior.
Generated-By: PostHog Code
Task-Id: 73be371c-908a-4f9f-9748-7ddba2df71e2
Uploaded manual files (RomFile with category="manual") were served from the
content endpoint as application/octet-stream + attachment, so the in-page
manual viewer showed a blank area while nav buttons and download still worked.
Include .pdf and .md in is_allowed_media_file (with explicit MIME overrides)
so they are served inline, and set X-Content-Type-Options: nosniff on inline
responses so a Markdown manual can't be sniffed into HTML.
Fixes#3712
Generated-By: PostHog Code
Task-Id: 73be371c-908a-4f9f-9748-7ddba2df71e2
Restrict extracted audio cover bytes to JPEG/PNG via magic-byte sniffing
instead of trusting the declared MP4 imageformat, so a GIF (or missing
format) is no longer mislabeled and persisted as image/jpeg.
The direct ROM-file endpoints (`get_romfile` and `get_romfile_content`)
resolved a RomFile purely by its user-supplied id and never mapped it
back to the parent Rom, so an authenticated user with roms.read could
read or download a file of a ROM hidden from them by knowing/guessing
the RomFile.id, bypassing the hidden ROM/platform policy.
Resolve the parent Rom and apply assert_rom_visible (404-masking) before
returning any file bytes or metadata, matching the ROM-level content
endpoints and the existing check in patch.py.
Generated-By: PostHog Code
Task-Id: 149c191c-7a22-4cf6-aafd-4dcf53f4fba0
The v2 patcher tab now appears for every game, not only ROMs that bundle
nested patch files. The patch source can be either a library patch file
(as before) or a patch uploaded from disk, which is applied server-side
and never stored in the library, so users don't have to keep patches
around until they need them. Download and upload-to-RomM options are
unchanged.
Backend: POST /roms/{id}/patch now accepts multipart form data with
either patch_file_id or an uploaded patch_file (exactly one). The upload
is streamed to a temp dir in bounded chunks, validated for extension and
size, applied, and removed after streaming. Scope stays ROMS_READ since
the patch is temp-only.
Frontend: added a Library/Upload source toggle (shown only when the ROM
bundles patches) using RDropzone, and the request now sends FormData.
Regenerated OpenAPI types and dropped the now-unused no-patch-files key.
Generated-By: PostHog Code
Task-Id: d0fc3734-585d-44bc-aaa9-481a3cd6a23b
Manually (re)matching a LaunchBox ID through the ROM edit dialog never
imported any LaunchBox media. The update_rom endpoint fetched metadata
without fs_name/platform_slug (so local media never resolved), never
generated media paths, and had no store loop, unlike the ScreenScraper
block in the same handler.
Pass fs_name/platform_slug to get_rom_by_id, call
populate_rom_specific_paths on the fetched metadata, and add a
store_media_file loop that also clears stale media when the ID changes.
Fixes#3521
Generated-By: PostHog Code
Task-Id: 45791732-58e8-41c9-b616-4a91018e388d
Discover manuals only for the allowed extensions (.pdf, .md) instead of
globbing {rom.id}.*, so stray files (e.g. {rom.id}.part) are never treated
as a manual. Select deterministically by newest mtime when multiple allowed
manuals coexist. Drop the redundant .md token from the frontend accept lists.
Generated-By: PostHog Code
Task-Id: 1d785bcc-ea5c-4b99-b619-73625a9e218c
- Extend GET /api/roms/download to accept collection_id,
virtual_collection_id or smart_collection_id as an alternative to
rom_ids, with owner/public access checks and the zip named after
the collection
- v2 SelectionBar: bundle multi-selections into a single server-side
zip instead of one anchor download per ROM (#3641)
- v2 collection head: add a download-collection action that downloads
by collection id, independent of gallery pagination (#3659)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
RomM stores soundtracks but exposes no way to consume them as a music library: a
client has to enumerate ROMs and pull each one's tracks individually, and the
per-track metadata lives in the `rom_files.audio_meta` JSON blob, which is
unindexable on MariaDB, so any library-wide filter or sort degrades to a full
scan.
This adds a queryable, music-first API for soundtracks, backed by a typed and
indexed `track_meta` table migrated from that JSON.
It also lets users upload soundtracks, manuals, and screenshots to any ROM, not
only folder-based ones. When the target is a single-file ROM, the client warns
that the upload will migrate it to a multi-file (folder) structure, then performs
that migration in place automatically.
Chunked ROM uploads created their temp directory directly under
ROMM_BASE_PATH (/romm/tmp/uploads). The bare /romm directory is owned by
the image's romm user (1000:1000, mode 755), so containers running with a
custom UID/GID cannot create directories there, causing uploads to fail
with "PermissionError: [Errno 13] Permission denied: '/romm/tmp'".
Default the upload temp root to RESOURCES_BASE_PATH instead, which is a
writable mounted volume in those setups (this is why manual uploads, which
write under resources/, already worked). ROMM_TMP_PATH still overrides it.
Fixes#3574
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014ficBAiEtYtZyBY8nWExKh
Adds a "Tag" gallery filter so a library can be narrowed by the custom
tags parsed from filenames (No-Intro / Redump nomenclature, e.g. Proto,
Beta, Demo), mirroring the existing data-derived multi-value filters
(regions, languages). Closes#3546.
Backend:
- New `_filter_by_tags` over `Rom.tags` with any/all/none logic; wired
through filter_roms, get_roms_scalar, the /roms endpoint (tags +
tags_logic), and the unscoped cache gate.
- Tags are data-derived, so the selectable list is surfaced via
filter_values: added to _collect_filter_values, with_filter_values,
get_rom_filters, and RomFiltersDict.
- Smart collections apply the criterion via get_smart_collection_roms.
Frontend (v1 + v2):
- Wired into the galleryFilter store, rom API service, request cache key,
both filter drawers, v2 URL persistence, the v2 refetch watcher, and
smart-collection serialization/summary + create dialog.
- Added the `platform.tag` key to all locales (distinct from the existing
`platform.tags` section heading).
Tests:
- Backend handler (any/all/none + unknown-value), endpoint, filter_values,
and smart-collection coverage.
- Frontend smartCollectionCriteria serialization/summary coverage.
AI assistance: implemented with Claude Code (Anthropic).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Visibility-coverage gaps (404-mask hidden entities, mirroring the existing
delete/read paths):
- update_rom (PUT /roms/{id}) and update_rom_user (PUT /roms/{id}/props)
- add_firmware: platform-hide now cascades to firmware uploads
- patch_rom: resolve the parent rom of both the base and patch files and
404 when hidden, so a hidden rom's bytes can no longer be streamed back
- activity feeds (get_all_activity / get_rom_activity): drop sessions whose
rom is hidden from the caller
Migration: make the role enum -> varchar narrowing Postgres-safe. The cast
now uses postgresql_using, the orphaned native role type is dropped on
upgrade, and downgrade recreates it explicitly (create_type=False) before
re-typing the column. Verified up/down/up on Postgres 16 and MariaDB.
Also collapses the two permission migrations into a single 0092 and notes
the override own_only replacement granularity limit in the resolver.
AI assistance: implemented with Claude Code (review-fix pass).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds a "Metadata provider" gallery filter so a library can be narrowed by
which providers each ROM matched (IGDB, MobyGames, ScreenScraper, etc.),
mirroring the existing multi-value filters (player count, age rating).
Backend:
- New `_filter_by_metadata_providers` keyed off each provider's id column
on Rom, with any/all/none logic; wired through filter_roms,
get_roms_scalar, the /roms endpoint, and the unscoped cache gate.
- Smart collections apply the criterion via get_smart_collection_roms.
- Unknown provider slugs are ignored (no-op) so stale bookmarks or
hand-edited URLs don't error.
Frontend (v1 + v2):
- Shared METADATA_PROVIDER_OPTIONS registry; provider list is a fixed set
rather than data-derived, so options are static.
- Wired into the galleryFilter store, rom API service, request cache key,
both filter drawers, v2 URL persistence, the v2 refetch watcher, and
smart-collection serialization/summary.
- Added the `platform.metadata-provider` key to all locales.
Tests:
- Backend handler, endpoint, and smart-collection coverage (any/all/none
plus unknown-slug).
- Frontend smartCollectionCriteria serialization/summary coverage.
Also normalized collections_handler.py to LF (it was the only CRLF file in
the backend, which tripped git-diff-check on the edited lines).
AI assistance: implemented with Claude Code (Anthropic).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>