Commit Graph

145 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
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
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
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
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
9488ceba0e Merge pull request #3167 from tmgast/fix/mod-zip-range-requests
feat: Support Range requests for multi-file ROM downloads
2026-07-19 18:32:12 -04:00
Georges-Antoine Assi
02f4897979 refactor: drop failed_items from BulkOperationResponse
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>
2026-07-19 12:30:01 -04:00
Georges-Antoine Assi
25910518f8 fix(v2): keep failed ROMs selected on partial delete
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>
2026-07-19 12:13:41 -04:00
Georges-Antoine Assi
cf1420bd5d Merge branch 'master' into fix/mod-zip-range-requests 2026-07-18 18:15:39 -04:00
Georges-Antoine Assi
fe32918b46 refactor: simplify ZIP cache range-request support
- 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
2026-07-16 21:55:28 -04:00
Georges-Antoine Assi
bc602972c7 cleanup 2026-07-16 21:00:57 -04:00
Georges-Antoine Assi
6ca8d943b2 Merge branch 'master' into posthog-code/roms-optional-id-index 2026-07-16 20:58:46 -04:00
Georges-Antoine Assi
2321468a67 perf(roms): make full rom id index opt-out on GET /api/roms
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
2026-07-16 18:37:27 -04:00
Georges-Antoine Assi
9b6acf66b4 fix(backend): lightweight eager-load for /roms/{id}/simple
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
2026-07-16 16:01:59 -04:00
Georges-Antoine Assi
9aac4c7193 Update backend/endpoints/roms/files.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-07-15 19:21:59 -04:00
copilot-swe-agent[bot]
0f8a9b67b4 feat: add file deletion to FilesTab with backend endpoint and permission guard
- 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>
2026-07-15 13:31:44 +00:00
Georges-Antoine Assi
d587fc7034 fix(backend): scope inline document serving to manual-category files
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
2026-07-09 19:56:53 -04:00
Georges-Antoine Assi
def9258636 fix(backend): serve PDF/Markdown manuals inline so the viewer can render them
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
2026-07-09 19:38:16 -04:00
VoidHandler
20132dfbcb format code 2026-07-08 21:56:49 -04:00
VoidHandler
efa5945f03 fix(backend): validate embedded cover format and surface extraction failures
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.
2026-07-08 00:33:43 -04:00
Georges-Antoine Assi
ff2aa0d7d7 Merge pull request #3700 from rommapp/posthog-code/display-media-files-in-details-tab
feat(roms): serve and display media files inline in details tab
2026-07-07 12:00:40 -04:00
Georges-Antoine Assi
3e1212e38d cleanup 2026-07-07 10:57:53 -04:00
Georges-Antoine Assi
3abd0829b7 fix(roms): enforce parent ROM visibility on direct file endpoints
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
2026-07-07 09:28:27 -04:00
Georges-Antoine Assi
3348d9bb29 cleanup 2026-07-06 22:17:56 -04:00
Georges-Antoine Assi
15e24629a3 feat: display library media files in artwork gallery and overview
Generated-By: PostHog Code
2026-07-06 21:54:44 -04:00
Georges-Antoine Assi
32757d838a feat(patcher): always show patcher tab and allow uploading a patch
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
2026-07-06 10:39:11 -04:00
Georges-Antoine Assi
40cdeac615 fix(launchbox): import local media when matching via update_rom
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
2026-07-05 17:53:50 -04:00
Georges-Antoine Assi
e7de380aac fix(roms): restrict manual matching to allowed extensions
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
2026-07-05 12:20:41 -04:00
Georges-Antoine Assi
82bd5e30b8 feat(roms): support markdown manuals and enforce allowed file types
Generated-By: PostHog Code
2026-07-05 08:49:47 -04:00
Georges-Antoine Assi
f3cc451615 add back backend 2026-07-04 14:12:16 -04:00
Georges-Antoine Assi
ab02c2c262 cleanup 2026-07-04 13:02:54 -04:00
Georges-Antoine Assi
e0fc0badb8 simplification 2026-07-04 12:49:31 -04:00
Georges-Antoine Assi
281f79c8e0 Merge branch 'master' into fix/collection-bulk-download 2026-07-04 12:42:31 -04:00
Spinnich
9f58919612 fix(collections): download whole collections as one zip (#3641, #3659)
- 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>
2026-07-02 16:50:27 +00:00
nendo
8a94854b81 Add a music query API for soundtracks
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.
2026-07-02 11:16:07 +09:00
Georges-Antoine Assi
71d5d3a47f refactor raw endpoint 2026-07-01 08:58:00 -04:00
Georges-Antoine Assi
69aad95282 remove comments 2026-06-29 19:28:13 -04:00
Claude
f9a5537efc fix(upload): store chunk temp dir under writable resources path
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
2026-06-29 14:36:09 +00:00
Georges-Antoine Assi
cdbad10ab5 Merge pull request #3629 from Spinnich/feat/filter-by-custom-tags
feat(roms): filter games by custom tags
2026-06-29 10:27:18 -04:00
zurdi
9234efd386 Merge remote-tracking branch 'origin/master' into chore/permissions-system-rework
# Conflicts:
#	backend/handler/database/stats_handler.py
2026-06-29 11:33:03 +00:00
Spinnich
14a0a98661 feat(roms): filter games by custom tags
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>
2026-06-29 11:29:12 +00:00
Georges-Antoine Assi
e8aebbf006 Merge pull request #3615 from Spinnich/feat/filter-by-metadata-provider
feat(roms): filter games by matched metadata provider
2026-06-29 07:12:40 -04:00
zurdi
e6225e582a refactor(permissions): replace get_permissions checks with assert_platform_visible and assert_rom_visible for better clarity and maintainability 2026-06-29 10:11:02 +00:00
zurdi
7d45795408 fix(permissions): address gantoine review + Postgres-safe single migration
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>
2026-06-26 22:10:00 +00:00
zurdi
5303130d15 Merge remote-tracking branch 'origin/master' into chore/permissions-system-rework 2026-06-26 15:35:41 +00:00
Spinnich
983f016efe feat(roms): filter games by matched metadata provider
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>
2026-06-26 13:52:19 +00:00