mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-25 18:35:07 +00:00
fix(remote): forward nested service cache files to and from the server
Cache keys are now the path relative to the service cache dir without .json, so Cacher keys like session_web/<sha1> reach the remote session. The credential filter runs on every path segment, the suffix is appended rather than substituted, and both sides cap the map at 64 keys.
This commit is contained in:
@@ -21,7 +21,7 @@ from aiohttp import web
|
||||
from unshackle.core.api.compression import safe_inflate
|
||||
from unshackle.core.api.errors import APIError, APIErrorCode, categorize_exception, handle_api_exception
|
||||
from unshackle.core.api.input_bridge import AuthStatus, InputBridge
|
||||
from unshackle.core.api.sanitize import safe_cache_key, sanitize_log
|
||||
from unshackle.core.api.sanitize import MAX_SESSION_CACHE_KEYS, safe_cache_key, sanitize_log
|
||||
from unshackle.core.api.session_log import SessionLogBuffer, SessionLogMirror, capture_service_logs
|
||||
from unshackle.core.api.session_store import SessionStore
|
||||
from unshackle.core.cacher import Cacher
|
||||
@@ -1111,7 +1111,6 @@ def drm_preference_name(track: Any) -> Optional[str]:
|
||||
|
||||
|
||||
MANIFEST_DATA_KEYS = ("hls", "dash", "ism")
|
||||
MAX_SESSION_CACHE_KEYS = 64
|
||||
|
||||
|
||||
def serialize_track_data(track: Any) -> Optional[Dict[str, Any]]:
|
||||
@@ -3016,7 +3015,12 @@ async def session_create_handler(data: Dict[str, Any], request: Optional[web.Req
|
||||
if not isinstance(content, str):
|
||||
raise APIError(APIErrorCode.INVALID_INPUT, "cache values must be base64 strings")
|
||||
decompressed = safe_inflate(base64.b64decode(content)).decode("utf-8")
|
||||
(cache_dir / safe_name).with_suffix(".json").write_text(decompressed, encoding="utf-8")
|
||||
target = cache_dir / f"{safe_name}.json"
|
||||
try:
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text(decompressed, encoding="utf-8")
|
||||
except OSError as e:
|
||||
log.warning(f"Skipping session cache key {sanitize_log(key)}: {e}")
|
||||
|
||||
bridge = InputBridge()
|
||||
service_instance._input_bridge = bridge
|
||||
@@ -4452,12 +4456,14 @@ async def session_delete_handler(session_id: str, request: Optional[web.Request]
|
||||
if cache_tag and session.client_auth:
|
||||
cache_dir = app_config.directories.cache / cache_tag
|
||||
if cache_dir.is_dir():
|
||||
for f in cache_dir.glob("*.json"):
|
||||
if not f.stem.startswith("titles_"):
|
||||
try:
|
||||
cache_data[f.stem] = base64.b64encode(zlib.compress(f.read_bytes())).decode("ascii")
|
||||
except OSError:
|
||||
pass
|
||||
for f in sorted(cache_dir.rglob("*.json")):
|
||||
key = f.relative_to(cache_dir).as_posix()[: -len(".json")]
|
||||
if f.stem.startswith("titles_") or not safe_cache_key(key):
|
||||
continue
|
||||
try:
|
||||
cache_data[key] = base64.b64encode(zlib.compress(f.read_bytes())).decode("ascii")
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
await store.delete(session_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user