Initial import: Music_Server, MusicFree, catalog-sync

This commit is contained in:
2026-05-23 16:51:14 +08:00
commit 069af30dba
847 changed files with 179878 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
from pathlib import Path
from music_server.services.token_service import TokenService
_TOKEN_CACHE: dict[tuple[str, str], str] = {}
def issue_access_token(player_db_path: str | Path, *, label: str = "test-token") -> str:
cache_key = (str(player_db_path), label)
cached = _TOKEN_CACHE.get(cache_key)
if cached is not None:
return cached
service = TokenService(str(player_db_path))
issued = service.issue_token(label=label).plaintext_token
_TOKEN_CACHE[cache_key] = issued
return issued
def auth_headers(
player_db_path: str | Path,
*,
client_id: str = "test-client",
client_label: str = "Test Client",
token: str | None = None,
include_client_id: bool = True,
include_client_label: bool = True,
) -> dict[str, str]:
issued_token = token or issue_access_token(player_db_path)
headers = {"Authorization": f"Bearer {issued_token}"}
if include_client_id:
headers["X-Music-Client-Id"] = client_id
if include_client_label:
headers["X-Music-Client-Label"] = client_label
return headers