Refactor and enhance OAuth2.0 implementation; update models and routes
- Refactored AdminSummaryData and AdminSummaryResponse classes for better clarity. - Added OAUTH type to SettingsType enum. - Cleaned up imports in webdav.py. - Updated admin router to improve summary data retrieval and response handling. - Enhanced file management routes with better condition handling and user storage updates. - Improved group management routes by optimizing data retrieval. - Refined task management routes for better condition handling. - Updated user management routes to streamline access token retrieval. - Implemented a new captcha verification structure with abstract base class. - Removed deprecated env.md file and replaced with a new structured version. - Introduced a unified OAuth2.0 client base class for GitHub and QQ integrations. - Enhanced password management with improved hashing strategies. - Added detailed comments and documentation throughout the codebase for clarity.
This commit is contained in:
@@ -2,14 +2,12 @@ from datetime import datetime, timedelta
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from loguru import logger as l
|
||||
from sqlalchemy import and_
|
||||
|
||||
from middleware.auth import admin_required
|
||||
from middleware.dependencies import SessionDep
|
||||
from models import (
|
||||
User, ResponseBase,
|
||||
Setting, Object, ObjectType, Share, AdminSummaryResponse, MetricsSummary, LicenseInfo, VersionInfo,
|
||||
AdminSummaryData,
|
||||
)
|
||||
from models.base import SQLModelBase
|
||||
from models.setting import (
|
||||
@@ -75,8 +73,8 @@ async def router_admin_get_summary(session: SessionDep) -> AdminSummaryResponse:
|
||||
Returns:
|
||||
AdminSummaryResponse: 包含站点概况信息的响应模型。
|
||||
"""
|
||||
# 统计最近 12 天的数据
|
||||
days_count = 12
|
||||
# 统计最近 14 天的数据
|
||||
days_count = 14
|
||||
now = datetime.now()
|
||||
today_start = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
@@ -135,7 +133,7 @@ async def router_admin_get_summary(session: SessionDep) -> AdminSummaryResponse:
|
||||
site_urls: list[str] = []
|
||||
site_url_setting = await Setting.get(
|
||||
session,
|
||||
and_(Setting.type == SettingsType.BASIC, Setting.name == "siteURL"),
|
||||
(Setting.type == SettingsType.BASIC) & (Setting.name == "siteURL"),
|
||||
)
|
||||
if site_url_setting and site_url_setting.value:
|
||||
site_urls.append(site_url_setting.value)
|
||||
@@ -156,15 +154,13 @@ async def router_admin_get_summary(session: SessionDep) -> AdminSummaryResponse:
|
||||
commit="dev",
|
||||
)
|
||||
|
||||
data = AdminSummaryData(
|
||||
return AdminSummaryResponse(
|
||||
metrics_summary=metrics_summary,
|
||||
site_urls=site_urls,
|
||||
license=license_info,
|
||||
version=version_info,
|
||||
)
|
||||
|
||||
return AdminSummaryResponse(data=data)
|
||||
|
||||
@admin_router.get(
|
||||
path='/news',
|
||||
summary='获取社区新闻',
|
||||
@@ -203,7 +199,7 @@ async def router_admin_update_settings(
|
||||
for item in request.settings:
|
||||
existing = await Setting.get(
|
||||
session,
|
||||
and_(Setting.type == item.type, Setting.name == item.name)
|
||||
(Setting.type == item.type) & (Setting.name == item.name)
|
||||
)
|
||||
|
||||
if existing:
|
||||
@@ -245,7 +241,12 @@ async def router_admin_get_settings(
|
||||
if name:
|
||||
conditions.append(Setting.name == name)
|
||||
|
||||
condition = and_(*conditions) if conditions else None
|
||||
if conditions:
|
||||
condition = conditions[0]
|
||||
for c in conditions[1:]:
|
||||
condition = condition & c
|
||||
else:
|
||||
condition = None
|
||||
|
||||
settings = await Setting.get(session, condition, fetch_mode="all")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user