Files
disknext/models/setting.py
于小丘 a5efda9c23 feat(mixin): add TableBaseMixin and UUIDTableBaseMixin for async CRUD operations
- Implemented TableBaseMixin providing generic CRUD methods and automatic timestamp management.
- Introduced UUIDTableBaseMixin for models using UUID as primary keys.
- Added ListResponse for standardized paginated responses.
- Created TimeFilterRequest and PaginationRequest for filtering and pagination parameters.
- Enhanced get_with_count method to return both item list and total count.
- Included validation for time filter parameters in TimeFilterRequest.
- Improved documentation and usage examples throughout the code.
2025-12-22 18:29:14 +08:00

83 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import Literal
from enum import StrEnum
from sqlmodel import Field, UniqueConstraint
from .base import SQLModelBase
from .mixin import TableBaseMixin
# ==================== DTO 模型 ====================
class SiteConfigResponse(SQLModelBase):
"""站点配置响应 DTO"""
title: str = "DiskNext"
"""网站标题"""
themes: dict[str, str] = {}
"""网站主题配置"""
default_theme: dict[str, str] = {}
"""默认主题RGB色号"""
site_notice: str | None = None
"""网站公告"""
user: dict[str, str | int | bool] = {}
"""用户信息"""
logo_light: str | None = None
"""网站Logo URL"""
logo_dark: str | None = None
"""网站Logo URL深色模式"""
captcha_type: Literal["none", "default", "gcaptcha", "cloudflare turnstile"] = "none"
"""验证码类型"""
captcha_key: str | None = None
"""验证码密钥"""
# ==================== 数据库模型 ====================
class SettingsType(StrEnum):
"""设置类型枚举"""
ARIA2 = "aria2"
AUTH = "auth"
AUTHN = "authn"
AVATAR = "avatar"
BASIC = "basic"
CAPTCHA = "captcha"
CRON = "cron"
FILE_EDIT = "file_edit"
LOGIN = "login"
MAIL = "mail"
MAIL_TEMPLATE = "mail_template"
MOBILE = "mobile"
PATH = "path"
PREVIEW = "preview"
PWA = "pwa"
REGISTER = "register"
RETRY = "retry"
SHARE = "share"
SLAVE = "slave"
TASK = "task"
THUMB = "thumb"
TIMEOUT = "timeout"
UPLOAD = "upload"
VERSION = "version"
VIEW = "view"
WOPI = "wopi"
# 数据库模型
class Setting(SQLModelBase, TableBaseMixin):
"""设置模型"""
__table_args__ = (UniqueConstraint("type", "name", name="uq_setting_type_name"),)
type: SettingsType = Field(max_length=255, description="设置类型/分组")
name: str = Field(max_length=255, description="设置项名称")
value: str | None = Field(default=None, description="设置值")