Files
disknext/models/setting.py
于小丘 abd85e2290 Refactor auth and unify error handling in routers
Renamed AuthRequired/AdminRequired to auth_required/admin_required and updated all references. Replaced direct HTTPException usage with utils.http_exceptions for consistent error handling. Updated router endpoints to use new auth dependency and standardized not implemented responses. Cleaned up unused theme fields in SiteConfigResponse and improved site config endpoint. Minor type and import cleanups across routers and middleware.
2025-12-25 19:08:46 +08:00

119 lines
2.5 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 enum import StrEnum
from sqlmodel import UniqueConstraint
from .base import SQLModelBase
from .mixin import TableBaseMixin
from .user import UserResponse
class CaptchaType(StrEnum):
"""验证码类型枚举"""
DEFAULT = "default"
GCAPTCHA = "gcaptcha"
CLOUD_FLARE_TURNSTILE = "cloudflare turnstile"
# ==================== DTO 模型 ====================
class SiteConfigResponse(SQLModelBase):
"""站点配置响应 DTO"""
title: str = "DiskNext"
"""网站标题"""
# themes: dict[str, str] = {}
# """网站主题配置"""
# default_theme: dict[str, str] = {}
# """默认主题RGB色号"""
site_notice: str | None = None
"""网站公告"""
user: UserResponse
"""用户信息"""
logo_light: str | None = None
"""网站Logo URL"""
logo_dark: str | None = None
"""网站Logo URL深色模式"""
captcha_type: CaptchaType | None = None
"""验证码类型"""
captcha_key: str | None = None
"""验证码密钥"""
# ==================== 管理员设置 DTO ====================
class SettingItem(SQLModelBase):
"""设置项 DTO"""
name: str
"""设置项名称"""
value: str | None = None
"""设置值"""
class SettingsUpdateRequest(SQLModelBase):
"""更新设置请求 DTO"""
settings: dict[str, dict[str, str | None]]
"""按类型分组的设置项,格式: {"basic": {"siteName": "xxx", ...}, ...}"""
class SettingsGetResponse(SQLModelBase):
"""获取设置响应 DTO"""
settings: dict[str, dict[str, str | 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
"""设置类型/分组"""
name: str
"""设置项名称"""
value: str | None
"""设置值"""