33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from pydantic import field_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
from pathlib import Path
|
|
import os
|
|
|
|
|
|
class Config(BaseSettings):
|
|
"""Points system configuration."""
|
|
|
|
model_config = SettingsConfigDict(
|
|
extra="ignore",
|
|
)
|
|
|
|
# 数据库配置
|
|
POINTS_DB_FILE: str = os.getenv("DANDING_POINTS_DB_FILE", "data/danding_points/points.db")
|
|
POINTS_MAX_BALANCE: int = int(os.getenv("DANDING_POINTS_MAX_BALANCE", "0"))
|
|
POINTS_MAX_PER_OPERATION: int = int(os.getenv("DANDING_POINTS_MAX_PER_OPERATION", "0"))
|
|
POINTS_LOG_RETENTION_DAYS: int = int(os.getenv("DANDING_POINTS_LOG_RETENTION_DAYS", "365"))
|
|
|
|
@field_validator("POINTS_MAX_BALANCE", "POINTS_MAX_PER_OPERATION", "POINTS_LOG_RETENTION_DAYS")
|
|
@classmethod
|
|
def validate_non_negative(cls, v):
|
|
if v < 0:
|
|
raise ValueError("Value must be non-negative")
|
|
return v
|
|
|
|
@field_validator("POINTS_DB_FILE")
|
|
@classmethod
|
|
def validate_db_path(cls, v):
|
|
if not v:
|
|
raise ValueError("Database file path cannot be empty")
|
|
return v
|