Update codebase and add coverage report
Removed an old run configuration, added a new coverage XML report, and updated multiple source files including main.py, middleware, models, routers, services, tests, and utility modules. Also updated pyproject.toml and the lock file. These changes likely include code improvements, test coverage updates, and dependency adjustments.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from loguru import logger as log
|
||||
|
||||
@@ -13,104 +14,11 @@ BackendVersion = "0.0.1"
|
||||
|
||||
IsPro = False
|
||||
|
||||
mode: str = os.getenv('MODE', 'master')
|
||||
|
||||
debug: bool = os.getenv("DEBUG", "false").lower() in ("true", "1", "yes") or False
|
||||
|
||||
if debug:
|
||||
log.info("Debug mode is enabled. This is not recommended for production use.")
|
||||
log.warning("Debug mode is enabled. This is not recommended for production use.")
|
||||
|
||||
database_url: str = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///disknext.db")
|
||||
|
||||
tags_meta = [
|
||||
{
|
||||
"name": "site",
|
||||
"description": "站点",
|
||||
},
|
||||
{
|
||||
"name": "user",
|
||||
"description": "用户",
|
||||
},
|
||||
{
|
||||
"name": "user_settings",
|
||||
"description": "用户设置",
|
||||
},
|
||||
{
|
||||
"name": "share",
|
||||
"description": "分享",
|
||||
},
|
||||
{
|
||||
"name": "file",
|
||||
"description": "文件",
|
||||
},
|
||||
{
|
||||
"name": "aria2",
|
||||
"description": "离线下载",
|
||||
},
|
||||
{
|
||||
"name": "directory",
|
||||
"description": "目录",
|
||||
},
|
||||
{
|
||||
"name": "object",
|
||||
"description": "对象,文件和目录的抽象",
|
||||
},
|
||||
{
|
||||
"name": "callback",
|
||||
"description": "回调接口",
|
||||
},
|
||||
{
|
||||
"name": "oauth",
|
||||
"description": "OAuth 认证",
|
||||
},
|
||||
{
|
||||
"name": "pay",
|
||||
"description": "支付回调",
|
||||
},
|
||||
{
|
||||
"name": "upload",
|
||||
"description": "上传回调",
|
||||
},
|
||||
{
|
||||
"name": "vas",
|
||||
"description": "增值服务",
|
||||
},
|
||||
{
|
||||
"name": "tag",
|
||||
"description": "用户标签",
|
||||
},
|
||||
{
|
||||
"name": "webdav",
|
||||
"description": "WebDAV管理相关",
|
||||
},
|
||||
{
|
||||
"name": "admin",
|
||||
"description": "管理员接口",
|
||||
},
|
||||
{
|
||||
"name": "admin_group",
|
||||
"description": "管理员组接口",
|
||||
},
|
||||
{
|
||||
"name": "admin_user",
|
||||
"description": "管理员用户接口",
|
||||
},
|
||||
{
|
||||
"name": "admin_file",
|
||||
"description": "管理员文件接口",
|
||||
},
|
||||
{
|
||||
"name": "admin_aria2",
|
||||
"description": "管理员离线下载接口",
|
||||
},
|
||||
{
|
||||
"name": "admin_policy",
|
||||
"description": "管理员策略接口",
|
||||
},
|
||||
{
|
||||
"name": "admin_task",
|
||||
"description": "管理员任务接口",
|
||||
},
|
||||
{
|
||||
"name": "admin_vas",
|
||||
"description": "管理员增值服务接口",
|
||||
}
|
||||
]
|
||||
database_url: str = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///disknext.db")
|
||||
@@ -4,60 +4,60 @@ from fastapi import HTTPException, status
|
||||
|
||||
# --- 400 ---
|
||||
|
||||
def ensure_request_param(to_check: Any, detail: str) -> None:
|
||||
def ensure_request_param(to_check: Any, *args, **kwargs) -> None:
|
||||
"""
|
||||
Ensures a parameter exists. If not, raises a 400 Bad Request.
|
||||
This function returns None if the check passes.
|
||||
"""
|
||||
if not to_check:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, *args, **kwargs)
|
||||
|
||||
def raise_bad_request(detail: str = '') -> NoReturn:
|
||||
def raise_bad_request(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 400 Bad Request exception."""
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, *args, **kwargs)
|
||||
|
||||
def raise_unauthorized(detail: str) -> NoReturn:
|
||||
def raise_unauthorized(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 401 Unauthorized exception."""
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, *args, **kwargs)
|
||||
|
||||
def raise_insufficient_quota(detail: str = "积分不足,请充值") -> NoReturn:
|
||||
def raise_insufficient_quota(detail: str = "积分不足,请充值", *args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 402 Payment Required exception."""
|
||||
raise HTTPException(status_code=status.HTTP_402_PAYMENT_REQUIRED, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_402_PAYMENT_REQUIRED, detail=detail, *args, **kwargs)
|
||||
|
||||
def raise_forbidden(detail: str) -> NoReturn:
|
||||
def raise_forbidden(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 403 Forbidden exception."""
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, *args, **kwargs)
|
||||
|
||||
def raise_not_found(detail: str) -> NoReturn:
|
||||
def raise_not_found(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 404 Not Found exception."""
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, *args, **kwargs)
|
||||
|
||||
def raise_conflict(detail: str) -> NoReturn:
|
||||
def raise_conflict(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 409 Conflict exception."""
|
||||
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_409_CONFLICT, *args, **kwargs)
|
||||
|
||||
def raise_precondition_required(detail: str) -> NoReturn:
|
||||
def raise_precondition_required(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 428 Precondition required exception."""
|
||||
raise HTTPException(status_code=status.HTTP_428_PRECONDITION_REQUIRED, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_428_PRECONDITION_REQUIRED, *args, **kwargs)
|
||||
|
||||
def raise_too_many_requests(detail: str) -> NoReturn:
|
||||
def raise_too_many_requests(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 429 Too Many Requests exception."""
|
||||
raise HTTPException(status_code=status.HTTP_429_TOO_MANY_REQUESTS, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_429_TOO_MANY_REQUESTS, *args, **kwargs)
|
||||
|
||||
# --- 500 ---
|
||||
|
||||
def raise_internal_error(detail: str = "服务器出现故障,请稍后再试或联系管理员") -> NoReturn:
|
||||
def raise_internal_error(detail: str = "服务器出现故障,请稍后再试或联系管理员", *args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 500 Internal Server Error exception."""
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=detail, *args, **kwargs)
|
||||
|
||||
def raise_not_implemented(detail: str = "尚未支持这种方法") -> NoReturn:
|
||||
def raise_not_implemented(detail: str = "尚未支持这种方法", *args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 501 Not Implemented exception."""
|
||||
raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED, detail=detail, *args, **kwargs)
|
||||
|
||||
def raise_service_unavailable(detail: str) -> NoReturn:
|
||||
def raise_service_unavailable(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 503 Service Unavailable exception."""
|
||||
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, *args, **kwargs)
|
||||
|
||||
def raise_gateway_timeout(detail: str) -> NoReturn:
|
||||
def raise_gateway_timeout(*args, **kwargs) -> NoReturn:
|
||||
"""Raises an HTTP 504 Gateway Timeout exception."""
|
||||
raise HTTPException(status_code=status.HTTP_504_GATEWAY_TIMEOUT, detail=detail)
|
||||
raise HTTPException(status_code=status.HTTP_504_GATEWAY_TIMEOUT, *args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user