52 Commits

Author SHA1 Message Date
Sam Dornan
3204037797 fix(auth): validate reset passwords and make the last-admin guard atomic, with tests (#5106) 2026-10-04 10:18:15 -04:00
Sam Dornan
1dcda140e2 fix(rom): keep a disc an .m3u lists in place when promoting to a folder (#5076) 2026-10-03 13:37:24 -04:00
Ilyas Hallak
27ddb88967 feat(api): Add a REST endpoint to start a library scan (#5014)
* Add a REST endpoint to start a library scan

POST /api/tasks/scan queues a scan with the options of the `scan` socket
event, so clients authenticating with a bearer or client token can
start one without a Socket.IO session. It answers 202 with the queued job,
409 while a library scan is queued or running, and 503 when no worker
listens on the scan queue.

The enqueue path moves into queue_scan, shared with the socket handler.
A short Redis lock now covers the in-flight check and the enqueue, so two
requests landing on different web workers cannot both queue a library
scan. The socket handler also answers scan:done_ko for an unknown scan
type instead of raising.

* Default a scan without apis to the enabled sources, lease the request lock

A scan request that leaves out `apis` now uses every enabled metadata
source, on the REST endpoint and the socket alike, as the scheduled scan
and the watcher do. An explicit empty list still means no sources. The
web UI always sends `apis`, so its scans are unchanged.

redis_lock takes an optional lease_seconds, and the library scan request
lock holds its key for 30s while waiters give up after 5s, so a slow
holder cannot lose the lock to a waiter that then queues a second scan.

* Narrow optional mock call args in the new scan tests

* pr-ready step 2 (code-review): narrow the scan lock timeout handling to acquiring the lock

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* pr-ready step 3 (simplify): share the held-lock stub, read the task name off the queued job

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* pr-ready step 4 (review-polish): drop a test comment that recorded old behaviour

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Validate socket scan options with ScanPayload and list workers once per scan request

The socket handler now parses its options with the same ScanPayload the REST
endpoint uses, so an unknown key, scan type or metadata source answers
scan:done_ko instead of falling back to a scan of everything. v1 callers that
could send a null platform id now send a real one or none.

queue_scan checks for a live scan worker itself, so the socket also refuses a
scan no worker would pick up, and it lists the workers once for that check and
the in-flight check. The blocking RQ calls run in a thread, off the event loop.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Rename useScanProviders' ScanPayload to ScanSourceOptions

It shared its name with the generated ScanPayload request type while holding
only the metadata source options.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 18:46:28 -04:00
Zach Clendenen
0742f133e0 fix(api): apply code-review fixes for overlong names
pr-ready step 2 (code-review xhigh --fix): byte-check screenshot, rename
and ROM fs_name paths, fit streaming save archive names, cap email and
collection names, log duplicate collections at warning.
2026-10-01 10:34:16 -05:00
Zach Clendenen
438347615a fix(api): return 4xx for duplicate collections and overlong names
A duplicate collection name raised a 500. Names compare
case-insensitively in the database, so "TRUE" collides with "True".
Return 409 instead, as the existing test's name already said.

Memory card name and emulator, and the RetroAchievements username,
had no length check before the insert, so an overlong value failed in
the database with a 500. Validate them against their column lengths,
which returns 422.
2026-09-30 22:30:43 -05:00
Sam Dornan
fed6fc9172 refactor(db): follow-ups to the derived-state fixes (#4969) 2026-09-30 19:00:30 -04:00
Sam Dornan
6941de13db Remove unused code and deduplicate copied helpers (#4975) 2026-09-30 18:51:36 -04:00
nendo
f0c49b6a38 feat(devices): push downloads from the web UI to a device's download queue 2026-09-28 02:08:03 +09:00
Sam Dornan
3750d6ff70 chore(mypy): require full annotations outside tests, type the setup responses (#4795) 2026-09-26 15:31:00 -04:00
Georges-Antoine Assi
787bbba2b4 refactor(tasks): give every enqueue one home
Scheduling moved onto RQ, which left the task catalog with two identity
schemes: the registry key a job payload now carries, and the dotted func
path each PeriodicTask still declared. Nothing read the latter, so it is
gone, along with the test that guarded paths no payload names.

Four sites built the same enqueue by hand and had already drifted: the
startup backfills passed the global timeout and no result_ttl, so an
auto-enqueued conversion fell out of the task list after RQ's default
500s while the same task triggered by an admin lived for TASK_RESULT_TTL.
They now go through enqueue_task, which derives timeout, ttl and meta
from the task itself.

Scan discovery paid a Redis round trip per queued job to re-read a status
the fetch already carried, and the stale sweep read every delayed job to
find the few past due. Both now ask Redis once.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 21:03:30 -04:00
Sam Dornan
4e59217275 refactor(tasks): schedule with RQ instead of rq-scheduler
rq-scheduler has one release since 2023, 109 open issues, and RomM ran a
fork of it for Redis username and SSL options that upstream never took.
Everything it was here for now ships with RQ.

Its two failure modes were the reason for the workarounds in 9e9f59c04.
It reads a job's function name before taking the job out of its registry,
so one unreadable job stalls it for good; RQ's scheduler removes every id
it looked at whether or not the job could be read. And cancelling a
delayed job needed both `Scheduler.cancel` and `Job.cancel`, because the
first left the status alone and the second left the registry entry, which
the scheduler then queued anyway; `Job.cancel` on its own now clears the
scheduled registry.

Delayed jobs, which is how the watcher defers a rescan, go onto the queue
with `Queue.enqueue_in` and are released by the worker running with
`--with-scheduler`. Periodic tasks are declared in `tasks/cron_config.py`
and loaded by an `rq cron` process, replacing `rqscheduler`. A task is
registered only when it is enabled and has a cron string, so the
schedule-then-unschedule dance around the env toggles is gone, and with
it `PeriodicTask.init/schedule/unschedule`.

Jobs are enqueued by task name through `run_task_by_name`, resolved
against a catalog in `tasks/registry.py`. Nothing pickles a task instance
into Redis any more, which is what made a payload unreadable across
upgrades in the first place. The catalog also gives the tasks endpoint
one home for what a task is, rather than a list of its own.

Scan discovery keys off the type a job carries rather than the scheduled
rescan's function name, since every task now shares one entry point. That
also drops SCAN_LIBRARY_TASK_FUNC, which only existed to name a function
across an import cycle.

The watcher's dedupe worked on `job.args[0]` while scans are enqueued with
keyword arguments, so it never matched and every filesystem change
scheduled another scan. It reads `platform_ids` from the payload now, and
deliberately ignores a scan already running: that one may have walked past
the folder that just changed.

Startup clears what the old scheduler left in Redis, once.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 15:02:04 -05: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
661a5504d7 find a couple more uses 2026-02-09 17:26:21 -05:00
Georges-Antoine Assi
6cbf9bcbc2 run trunk fmt 2025-11-21 19:20:38 -05:00
Kieran Wood
7b8e6f1657 Added gemini-code-assist suggestions 2025-11-21 13:37:57 -07:00
Kieran Wood
0e4b7fd160 Fixed link to documentation in filestructure error 2025-11-21 13:25:28 -07:00
Georges-Antoine Assi
19b5a83261 Use default config values when config.yml not mount + show warning 2025-09-19 09:17:59 -04:00
Michael Manganiello
e4e3928d1b misc: Apply import sorting 2025-09-04 11:17:00 -03:00
Georges-Antoine Assi
51652d5084 make all path stuff async 2025-07-18 10:53:55 -04:00
Michael Manganiello
9ba787f6d1 fix: Remove critical log messages for 403 and 404 exceptions
These critical log messages are unnecessary and can clutter the logs,
based on user requests. This is even more notorious when RomM is
integrated to an error tracking system like Sentry.
2025-06-06 21:40:31 -03:00
zurdi
0670d2a695 refactor: enhance error messages with highlighted file names and platform details 2025-05-14 16:36:03 +00:00
zurdi
30a0be2c4c Merge branch 'master' into HEAD 2025-04-10 22:56:55 +00:00
zurdi
2a5bf1ab5b Add SGDBInvalidAPIKeyException for handling invalid API key errors 2025-04-01 09:52:33 +00:00
Georges-Antoine Assi
db26248f04 Remove disabled login check from login endpoint 2025-03-21 14:58:47 -04:00
Georges-Antoine Assi
04c31374af disable login endpoint as wel 2025-01-07 17:28:13 -05:00
Georges-Antoine Assi
34d49e6494 changes from self review 2024-12-13 11:33:39 -05:00
Georges-Antoine Assi
3abf50b056 changes from self review 2024-11-27 23:28:54 -05:00
Georges-Antoine Assi
bc5c2e45f3 wokring oidc setup with authentik 2024-11-26 23:57:15 -05:00
SaraVieira
9b298d46eb use env & reuse request 2024-09-10 21:00:20 +01:00
SaraVieira
2d39949aa0 show info on frontend 2024-09-08 16:35:30 +01:00
Michael Manganiello
2bfc3c4c7e misc: Refactor scan process by splitting single function
This change mainly refactors the `scan_platforms` function, moving part
of its logic to `_identify_platform`, `_identify_firmware`, and
`_identify_rom`.

The logic is simpler this way, each smaller function returns `ScanStats`
that can be merged by the caller, and it simplifies future performance
improvements.
2024-07-25 10:29:46 -03:00
Zurdi
23e0a064ab added update collection endpoint 2024-07-02 23:34:50 +02:00
Zurdi
857573e607 Merge remote-tracking branch 'origin/master' into feature/collections 2024-07-02 17:53:35 +02:00
Zurdi
4a413db4c5 fixes from PR review 2024-07-02 17:49:48 +02:00
Zurdi
cc9e05f668 collections migration added 2024-07-01 23:47:15 +02:00
zurdi
15f7522da5 rom db hanlder refactor to adapt to user_rom_props 2024-07-01 15:30:14 +02:00
Georges-Antoine Assi
880345f20c ruff-only pre-commit 2024-05-18 12:05:57 -04:00
Georges-Antoine Assi
eca1eb1136 model and scanning 2024-05-01 15:27:16 -04:00
zurdi
d3864ff02b create platform if not exists when adding roms fixed 2024-04-11 01:39:58 +02:00
zurdi
df047cc5e9 upload roms button in drawer added 2024-04-08 18:31:02 +02:00
Georges-Antoine Assi
2447c95ea6 update links to github 2024-03-23 10:11:55 -04:00
Zurdi
f1c5e02c32 config errors management improved 2024-01-18 11:46:12 +01:00
Zurdi
4b9e76f550 backend structure refactor 2024-01-12 23:44:27 +01:00
Georges-Antoine Assi
5762270f62 Merge branch 'master' into romm-55 2024-01-09 13:06:51 -05:00
Zurdi
eea7e41940 docstrings added to endpoints + organized imports + formatted code 2024-01-09 16:22:31 +01:00
Georges-Antoine Assi
cdafd680a0 Merge branch 'master' into romm-55 2024-01-05 15:38:05 -05:00
Zurdi
78152d91ee added backend endpoint to remove a platform 2024-01-05 11:48:56 +01:00
Georges-Antoine Assi
d4d929b29b Get upload and delete working 2023-11-23 20:47:27 -05:00
Georges-Antoine Assi
3965ca1997 Add basic auth + fix tests and typing 2023-08-23 11:21:01 -04:00
zurdi
f4f936f624 user avatar and enable/disable user support added 2023-08-23 14:16:31 +02:00