mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 01:58:41 +01:00
fix(screenscraper): re-add user credentials to media file downloads
SS media URLs are stripped of ssid/sspassword before DB storage (correct), but downloads were issued against the credential-less stored URLs, causing them to count against the anonymous IP quota instead of the user's account. Adds restore_sensitive_query_params() as the principled complement to strip_sensitive_query_params(), and add_ss_auth_to_url() in ss_handler which re-attaches credentials at download time without storing them. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,7 @@ from handler.filesystem import (
|
||||
)
|
||||
from handler.filesystem.roms_handler import FSRom
|
||||
from handler.metadata import meta_gamelist_handler, meta_hltb_handler
|
||||
from handler.metadata.ss_handler import get_preferred_media_types
|
||||
from handler.metadata.ss_handler import add_ss_auth_to_url, get_preferred_media_types
|
||||
from handler.redis_handler import get_job_func_name, high_prio_queue, redis_client
|
||||
from handler.scan_handler import (
|
||||
MetadataSource,
|
||||
@@ -401,7 +401,9 @@ async def _identify_rom(
|
||||
for media_type in preferred_media_types:
|
||||
if _added_rom.ss_metadata.get(f"{media_type.value}_path"):
|
||||
await fs_resource_handler.store_media_file(
|
||||
_added_rom.ss_metadata[f"{media_type.value}_url"],
|
||||
add_ss_auth_to_url(
|
||||
_added_rom.ss_metadata[f"{media_type.value}_url"]
|
||||
),
|
||||
_added_rom.ss_metadata[f"{media_type.value}_path"],
|
||||
)
|
||||
|
||||
|
||||
@@ -116,6 +116,16 @@ def strip_sensitive_query_params(
|
||||
return urlunparse(parsed._replace(query=new_query))
|
||||
|
||||
|
||||
def restore_sensitive_query_params(url: str, params: dict[str, str]) -> str:
|
||||
"""Add back key/value pairs previously stripped by strip_sensitive_query_params."""
|
||||
parsed = urlparse(url)
|
||||
qsl = parse_qsl(parsed.query, keep_blank_values=True)
|
||||
existing = {k.lower() for k in params}
|
||||
filtered = [(k, v) for k, v in qsl if k.lower() not in existing]
|
||||
new_query = urlencode(filtered + list(params.items()))
|
||||
return urlunparse(parsed._replace(query=new_query))
|
||||
|
||||
|
||||
class MetadataHandler(abc.ABC):
|
||||
SEARCH_TERM_SPLIT_PATTERN = re.compile(r"[\:\-\/]")
|
||||
SEARCH_TERM_NORMALIZER = re.compile(r"\s*[:-]\s+")
|
||||
|
||||
@@ -27,12 +27,28 @@ from .base_handler import (
|
||||
)
|
||||
from .base_handler import UniversalPlatformSlug as UPS
|
||||
from .base_handler import (
|
||||
restore_sensitive_query_params,
|
||||
strip_sensitive_query_params,
|
||||
)
|
||||
|
||||
SENSITIVE_KEYS = {"ssid", "sspassword"}
|
||||
|
||||
|
||||
def add_ss_auth_to_url(url: str) -> str:
|
||||
"""Re-add SS user credentials to a media URL at download time (never stored)."""
|
||||
creds = {
|
||||
k: v
|
||||
for k, v in {
|
||||
"ssid": SCREENSCRAPER_USER,
|
||||
"sspassword": SCREENSCRAPER_PASSWORD,
|
||||
}.items()
|
||||
if v
|
||||
}
|
||||
if not creds:
|
||||
return url
|
||||
return restore_sensitive_query_params(url, creds)
|
||||
|
||||
|
||||
def get_preferred_regions(rom: Rom | None = None) -> list[str]:
|
||||
"""Get preferred regions, prepending the rom's own region tags when available.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user