Add admin review and confirmation of cross-service user IDs
This commit is contained in:
@@ -46,6 +46,38 @@ class JellystatClient(ApiClient):
|
||||
raise JellystatError("Jellystat returned an unexpected library response")
|
||||
return {"connected": True}
|
||||
|
||||
async def check_user_ids(self, user_ids: list[str]) -> dict:
|
||||
"""Read metadata for known identities; never scan everyone's playback history."""
|
||||
if not self.configured():
|
||||
return {user_id: {"state": "not_configured"} for user_id in user_ids}
|
||||
results = {user_id: {"state": "unavailable"} for user_id in user_ids}
|
||||
semaphore = asyncio.Semaphore(6)
|
||||
async with httpx.AsyncClient(timeout=8.0) as client:
|
||||
async def check(user_id):
|
||||
if not re.fullmatch(r"[a-f0-9]{32}", user_id):
|
||||
return
|
||||
async with semaphore:
|
||||
try:
|
||||
response = await client.post(f"{self.base_url}/api/getUserDetails",
|
||||
headers={"x-api-token": self.api_key}, json={"userid": user_id})
|
||||
if response.status_code == 404 or (response.status_code == 200 and not response.content.strip()):
|
||||
results[user_id] = {"state": "missing"}
|
||||
return
|
||||
response.raise_for_status()
|
||||
row = response.json()
|
||||
if row is None:
|
||||
results[user_id] = {"state": "missing"}
|
||||
elif isinstance(row, dict) and same_user_id(row.get("Id"), user_id):
|
||||
results[user_id] = {"state": "matched", "id": user_id, "name": str(row.get("Name") or "")[:200]}
|
||||
except (httpx.HTTPError, ValueError):
|
||||
pass
|
||||
try:
|
||||
async with asyncio.timeout(25):
|
||||
await asyncio.gather(*(check(user_id) for user_id in user_ids))
|
||||
except TimeoutError:
|
||||
pass
|
||||
return results
|
||||
|
||||
async def get_user_history(self, user_id: str, start: datetime, end: datetime) -> tuple[list, list]:
|
||||
if not re.fullmatch(r"[A-Za-z0-9_-]{1,128}", user_id):
|
||||
raise JellystatError("Invalid linked Jellyfin identity")
|
||||
|
||||
Reference in New Issue
Block a user