This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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"
|
||||
token_secret: str = "development-only-change-me"
|
||||
token_ttl_seconds: int = 60 * 60 * 24 * 30
|
||||
cors_origins: str = "http://localhost:3001,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()
|
||||
|
||||
Reference in New Issue
Block a user