Files
pk-lab-server/src/pk_lab_server/config.py
T
codex-bot 434f324bb9
Verify and deploy API / verify-deploy (push) Failing after 1m45s
feat: persist authentication sessions in postgres
2026-09-18 22:16:30 +08:00

37 lines
1.3 KiB
Python

from functools import lru_cache
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
database_url: str = "sqlite:///./pk-lab.db"
session_ttl_seconds: int = 60 * 60 * 24 * 30
cors_origins: str = "http://localhost:3000,http://localhost:3002"
public_base_url: str = "http://localhost:18082"
test_auth_enabled: bool = False
xhs_token_url: str = "https://miniapp.xiaohongshu.com/api/rmp/token"
xhs_session_url: str = "https://miniapp.xiaohongshu.com/api/rmp/session"
xhs_hub_app_id: str = ""
xhs_hub_app_secret: str = Field(default="", repr=False)
xhs_rice_app_id: str = ""
xhs_rice_app_secret: str = Field(default="", repr=False)
@property
def cors_origin_list(self) -> list[str]:
return [item.strip() for item in self.cors_origins.split(",") if item.strip()]
def app_credentials(self, app_key: str) -> tuple[str, str]:
if app_key == "hub":
return self.xhs_hub_app_id, self.xhs_hub_app_secret
if app_key == "rice":
return self.xhs_rice_app_id, self.xhs_rice_app_secret
raise ValueError("unknown app_key")
@lru_cache
def get_settings() -> Settings:
return Settings()