mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 18:11:16 +01:00
Move the response cap onto MetadataHandler as _fetch_capped and route Demozoo, Pouet, and CSDb through it. Only CSDb was capped before, while Demozoo and Pouet read an unbounded body into memory before decoding it. Pouet's title search now streams too: an ambiguous title answers 200 with HTML we never parse, but the body was still being buffered. Validate youtube_video_id where it is read rather than where Demozoo parses it. The four metadata blobs it reads from are writable through the raw_*_metadata form fields, so the id reaching the embed URL never had to come from a provider, and IGDB and LaunchBox never checked it at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
32 lines
770 B
Python
32 lines
770 B
Python
import re
|
|
import uuid
|
|
from typing import Any, Final
|
|
|
|
from __version__ import __version__
|
|
|
|
# Embedded straight into a YouTube URL, so anything outside this must be dropped.
|
|
YOUTUBE_ID_RE: Final = re.compile(r"[A-Za-z0-9_-]{11}")
|
|
|
|
|
|
def get_version() -> str:
|
|
"""Returns current version tag"""
|
|
if __version__ != "<version>":
|
|
return __version__
|
|
|
|
return "development"
|
|
|
|
|
|
def is_valid_uuid(uuid_str: str) -> bool:
|
|
"""Check if a string is a valid UUID."""
|
|
try:
|
|
uuid.UUID(uuid_str, version=4)
|
|
return True
|
|
except ValueError:
|
|
return False
|
|
|
|
|
|
def valid_youtube_id(value: Any) -> str | None:
|
|
"""A video id, or None when it is not one."""
|
|
text = str(value or "")
|
|
return text if YOUTUBE_ID_RE.fullmatch(text) else None
|