mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 15:54:45 +01:00
refactor(scan): give the title id one resolver and one identity shape
The Tinfoil feed was left behind when `_switch_productid_format` changed from taking a `re.Match` to taking a `str`, so `/feeds/tinfoil` raised a TypeError for any Switch rom carrying a product id in its filename but no titledb id. It went unnoticed because `feeds.py` sits outside the changed files mypy sees. That call site was reachable only because "prefer the id the scan read over the one scraped from the filename" lived in a second helper above the lookup, leaving each caller to remember it. The resolution now happens inside `_switch_productid_format`, so the three providers and the feed all get it without repeating a preamble. Also: - Move `SWITCH_PLATFORM_SLUGS` to the sigil adapter so `utils/switch.py` stops importing the metadata base handler. The cycle that import created was papered over with a function-local import, and `normalize_identity` now takes the fact it needs rather than the whole slug set. - Merge a partial identity update onto the stored identity before normalizing it. Normalizing rewrites the whole triple, so a client sending only a title id was getting the derived base id next to its old save target. - Add `RomIdentity.from_rom` so the triple has one home on the read side too, and drop `asdict` from `as_rom_attrs`. - Hold the `SigilExtractionResult` on `TitleIdEmbedCandidate` instead of copying two of its fields. - Drop a guard in `_rom_level_identity` that could not fire, derive once in `normalize_identity`, and return only the parse from `_rebuild_rom_files`, which already owns `fs_rom["fs_name"]`. - Read the parsed config in the heartbeat rather than forcing a YAML re-parse per request, and make `SigilService.is_enabled` a classmethod like every other one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8db38f3322
commit
fbbadb7c86
15 files changed
+124
-124
No files matched your search
@@ -17,6 +17,7 @@ from tasks.scheduled.update_switch_titledb import (
|
||||
SWITCH_TITLEDB_INDEX_KEY,
|
||||
)
|
||||
from utils.context import ctx_httpx_client
|
||||
from utils.switch import derive_base_title_id
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models.rom import Rom
|
||||
@@ -276,21 +277,18 @@ class MetadataHandler(abc.ABC):
|
||||
|
||||
return search_term, None
|
||||
|
||||
@staticmethod
|
||||
def switch_product_id(rom: "Rom", fs_name: str) -> str | None:
|
||||
"""The Switch product id to search by, preferring the one the scan read
|
||||
out of the binary over one scraped from the filename."""
|
||||
if rom.title_id and SWITCH_PRODUCT_ID_REGEX.fullmatch(rom.title_id.upper()):
|
||||
return rom.title_id.upper()
|
||||
|
||||
match = SWITCH_PRODUCT_ID_REGEX.search(fs_name)
|
||||
return match.group(1) if match else None
|
||||
|
||||
async def _switch_productid_format(
|
||||
self, product_id: str, search_term: str
|
||||
self, rom: "Rom", fs_name: str, search_term: str
|
||||
) -> tuple[str, dict | None]:
|
||||
# Imported here because utils.switch imports this module for the slugs.
|
||||
from utils.switch import derive_base_title_id
|
||||
"""Match by Switch product id, preferring the one the scan read out of
|
||||
the binary over one scraped from the filename."""
|
||||
if rom.title_id and SWITCH_PRODUCT_ID_REGEX.fullmatch(rom.title_id.upper()):
|
||||
product_id = rom.title_id.upper()
|
||||
else:
|
||||
match = SWITCH_PRODUCT_ID_REGEX.search(fs_name)
|
||||
if not match:
|
||||
return search_term, None
|
||||
product_id = match.group(1)
|
||||
|
||||
# Updates and DLC share the base application's product ID, off by the
|
||||
# low 12 bits, and only the base has a titledb entry.
|
||||
|
||||
Reference in new issue
Block a user