Files
disknext/routers/api/v1/slave/__init__.py
于小丘 44a8959aa5 feat: 更新验证码请求模型,添加 Google reCAPTCHA 和 Cloudflare Turnstile 验证功能
refactor: 修改用户状态字段类型,优化用户模型
fix: 修复启动服务的错误提示信息
refactor: 统一认证依赖,替换为 AuthRequired
docs: 添加用户会话刷新接口
2025-12-25 10:26:45 +08:00

225 lines
5.9 KiB
Python

from fastapi import APIRouter, Depends
from fastapi.responses import FileResponse
from middleware.auth import AuthRequired
from models import ResponseBase
slave_router = APIRouter(
prefix="/slave",
tags=["slave"],
)
slave_aria2_router = APIRouter(
prefix="/aria2",
tags=["slave_aria2"],
)
@slave_router.get(
path='/ping',
summary='测试用路由',
description='Test route for checking connectivity.',
)
def router_slave_ping() -> ResponseBase:
"""
Test route for checking connectivity.
Returns:
ResponseBase: A response model indicating success.
"""
from utils.conf.appmeta import BackendVersion
return ResponseBase(data=BackendVersion)
@slave_router.post(
path='/post',
summary='上传',
description='Upload data to the server.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_post(data: str) -> ResponseBase:
"""
Upload data to the server.
Args:
data (str): The data to be uploaded.
Returns:
ResponseBase: A response model indicating success.
"""
pass
@slave_router.get(
path='/get/{speed}/{path}/{name}',
summary='获取下载',
)
def router_slave_download(speed: int, path: str, name: str) -> ResponseBase:
"""
Get download information.
Args:
speed (int): The speed of the download.
path (str): The path where the file is located.
name (str): The name of the file to be downloaded.
Returns:
ResponseBase: A response model containing download information.
"""
pass
@slave_router.get(
path='/download/{sign}',
summary='根据签名下载文件',
description='Download a file based on its signature.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_download_by_sign(sign: str) -> FileResponse:
"""
Download a file based on its signature.
Args:
sign (str): The signature of the file to be downloaded.
Returns:
FileResponse: A response containing the file to be downloaded.
"""
pass
@slave_router.get(
path='/source/{speed}/{path}/{name}',
summary='获取文件外链',
description='Get the external link for a file based on its signature.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_source(speed: int, path: str, name: str) -> ResponseBase:
"""
Get the external link for a file based on its signature.
Args:
speed (int): The speed of the download.
path (str): The path where the file is located.
name (str): The name of the file to be linked.
Returns:
ResponseBase: A response model containing the external link for the file.
"""
pass
@slave_router.get(
path='/source/{sign}',
summary='根据签名获取文件',
description='Get a file based on its signature.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_source_by_sign(sign: str) -> FileResponse:
"""
Get a file based on its signature.
Args:
sign (str): The signature of the file to be retrieved.
Returns:
FileResponse: A response containing the file to be retrieved.
"""
pass
@slave_router.get(
path='/thumb/{id}',
summary='获取缩略图',
description='Get a thumbnail image based on its ID.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_thumb(id: str) -> ResponseBase:
"""
Get a thumbnail image based on its ID.
Args:
id (str): The ID of the thumbnail image.
Returns:
ResponseBase: A response model containing the Base64 encoded thumbnail image.
"""
pass
@slave_router.delete(
path='/delete',
summary='删除文件',
description='Delete a file from the server.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_delete(path: str) -> ResponseBase:
"""
Delete a file from the server.
Args:
path (str): The path of the file to be deleted.
Returns:
ResponseBase: A response model indicating success or failure of the deletion.
"""
pass
@slave_aria2_router.post(
path='/test',
summary='测试从机连接Aria2服务',
description='Test the connection to the Aria2 service from the slave.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_aria2_test() -> ResponseBase:
"""
Test the connection to the Aria2 service from the slave.
"""
pass
@slave_aria2_router.get(
path='/get/{gid}',
summary='获取Aria2任务信息',
description='Get information about an Aria2 task by its GID.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_aria2_get(gid: str = None) -> ResponseBase:
"""
Get information about an Aria2 task by its GID.
Args:
gid (str): The GID of the Aria2 task.
Returns:
ResponseBase: A response model containing the task information.
"""
pass
@slave_aria2_router.post(
path='/add',
summary='添加Aria2任务',
description='Add a new Aria2 task.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_aria2_add(gid: str, url: str, options: dict = None) -> ResponseBase:
"""
Add a new Aria2 task.
Args:
gid (str): The GID for the new task.
url (str): The URL of the file to be downloaded.
options (dict, optional): Additional options for the task.
Returns:
ResponseBase: A response model indicating success or failure of the task addition.
"""
pass
@slave_aria2_router.delete(
path='/remove/{gid}',
summary='删除Aria2任务',
description='Remove an Aria2 task by its GID.',
dependencies=[Depends(AuthRequired)],
)
def router_slave_aria2_remove(gid: str) -> ResponseBase:
"""
Remove an Aria2 task by its GID.
Args:
gid (str): The GID of the Aria2 task to be removed.
Returns:
ResponseBase: A response model indicating success or failure of the task removal.
"""
pass