- Added user authentication and registration endpoints with JWT support. - Created tag management routes for creating and deleting tags. - Implemented value-added service (VAS) endpoints for managing storage packs and orders. - Developed WebDAV account management routes for creating, updating, and deleting accounts. - Introduced slave router for handling file uploads, downloads, and aria2 task management. - Enhanced JWT utility functions for token creation and secret key management. - Established lifespan management for FastAPI application startup and shutdown processes. - Integrated password handling utilities with Argon2 hashing and two-factor authentication support.
382 lines
9.7 KiB
Python
382 lines
9.7 KiB
Python
from fastapi import APIRouter, Depends, UploadFile
|
|
from fastapi.responses import FileResponse
|
|
from middleware.auth import SignRequired
|
|
from models.response import ResponseBase
|
|
|
|
file_router = APIRouter(
|
|
prefix="/file",
|
|
tags=["file"]
|
|
)
|
|
|
|
file_upload_router = APIRouter(
|
|
prefix="/file/upload",
|
|
tags=["file"]
|
|
)
|
|
|
|
@file_router.get(
|
|
path='/get/{id}/{name}',
|
|
summary='文件外链(直接输出文件数据)',
|
|
description='Get file external link endpoint.',
|
|
)
|
|
def router_file_get(id: str, name: str) -> FileResponse:
|
|
"""
|
|
Get file external link endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file.
|
|
name (str): The name of the file.
|
|
|
|
Returns:
|
|
FileResponse: A response containing the file data.
|
|
"""
|
|
pass
|
|
|
|
@file_router.get(
|
|
path='/source/{id}/{name}',
|
|
summary='文件外链(301跳转)',
|
|
description='Get file external link with 301 redirect endpoint.',
|
|
)
|
|
def router_file_source(id: str, name: str) -> ResponseBase:
|
|
"""
|
|
Get file external link with 301 redirect endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file.
|
|
name (str): The name of the file.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file with a redirect.
|
|
"""
|
|
pass
|
|
|
|
@file_upload_router.get(
|
|
path='/download/{id}',
|
|
summary='下载文件',
|
|
description='Download file endpoint.',
|
|
)
|
|
def router_file_download(id: str) -> ResponseBase:
|
|
"""
|
|
Download file endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to download.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file download.
|
|
"""
|
|
pass
|
|
|
|
@file_upload_router.get(
|
|
path='/archive/{sessionID}/archive.zip',
|
|
summary='打包并下载文件',
|
|
description='Archive and download files endpoint.',
|
|
)
|
|
def router_file_archive_download(sessionID: str) -> ResponseBase:
|
|
"""
|
|
Archive and download files endpoint.
|
|
|
|
Args:
|
|
sessionID (str): The session ID for the archive.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the archived files download.
|
|
"""
|
|
pass
|
|
|
|
@file_upload_router.post(
|
|
path='/{sessionID}/{index}',
|
|
summary='文件上传',
|
|
description='File upload endpoint.',
|
|
)
|
|
def router_file_upload(sessionID: str, index: int, file: UploadFile) -> ResponseBase:
|
|
"""
|
|
File upload endpoint.
|
|
|
|
Args:
|
|
sessionID (str): The session ID for the upload.
|
|
index (int): The index of the file being uploaded.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data.
|
|
"""
|
|
pass
|
|
|
|
@file_upload_router.put(
|
|
path='/',
|
|
summary='创建上传会话',
|
|
description='Create an upload session endpoint.',
|
|
dependencies=[Depends(SignRequired)],
|
|
)
|
|
def router_file_upload_session() -> ResponseBase:
|
|
"""
|
|
Create an upload session endpoint.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the upload session.
|
|
"""
|
|
pass
|
|
|
|
@file_upload_router.delete(
|
|
path='/{sessionID}',
|
|
summary='删除上传会话',
|
|
description='Delete an upload session endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_upload_session_delete(sessionID: str) -> ResponseBase:
|
|
"""
|
|
Delete an upload session endpoint.
|
|
|
|
Args:
|
|
sessionID (str): The session ID to delete.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the deletion.
|
|
"""
|
|
pass
|
|
|
|
@file_upload_router.delete(
|
|
path='/',
|
|
summary='清除所有上传会话',
|
|
description='Clear all upload sessions endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_upload_session_clear() -> ResponseBase:
|
|
"""
|
|
Clear all upload sessions endpoint.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for clearing all sessions.
|
|
"""
|
|
pass
|
|
|
|
@file_router.put(
|
|
path='/update/{id}',
|
|
summary='更新文件',
|
|
description='Update file information endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_update(id: str) -> ResponseBase:
|
|
"""
|
|
Update file information endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to update.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file update.
|
|
"""
|
|
pass
|
|
|
|
@file_router.post(
|
|
path='/create',
|
|
summary='创建空白文件',
|
|
description='Create a blank file endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_create() -> ResponseBase:
|
|
"""
|
|
Create a blank file endpoint.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file creation.
|
|
"""
|
|
pass
|
|
|
|
@file_router.put(
|
|
path='/download/{id}',
|
|
summary='创建文件下载会话',
|
|
description='Create a file download session endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_download(id: str) -> ResponseBase:
|
|
"""
|
|
Create a file download session endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to download.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file download session.
|
|
"""
|
|
pass
|
|
|
|
@file_router.get(
|
|
path='/preview/{id}',
|
|
summary='预览文件',
|
|
description='Preview file endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_preview(id: str) -> ResponseBase:
|
|
"""
|
|
Preview file endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to preview.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file preview.
|
|
"""
|
|
pass
|
|
|
|
@file_router.get(
|
|
path='/content/{id}',
|
|
summary='获取文本文件内容',
|
|
description='Get text file content endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_content(id: str) -> ResponseBase:
|
|
"""
|
|
Get text file content endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the text file.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the text file content.
|
|
"""
|
|
pass
|
|
|
|
@file_router.get(
|
|
path='/doc/{id}',
|
|
summary='获取Office文档预览地址',
|
|
description='Get Office document preview URL endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_doc(id: str) -> ResponseBase:
|
|
"""
|
|
Get Office document preview URL endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the Office document.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the Office document preview URL.
|
|
"""
|
|
pass
|
|
|
|
@file_router.get(
|
|
path='/thumb/{id}',
|
|
summary='获取文件缩略图',
|
|
description='Get file thumbnail endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_thumb(id: str) -> ResponseBase:
|
|
"""
|
|
Get file thumbnail endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to get the thumbnail for.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file thumbnail.
|
|
"""
|
|
pass
|
|
|
|
@file_router.post(
|
|
path='/source/{id}',
|
|
summary='取得文件外链',
|
|
description='Get file external link endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_source(id: str) -> ResponseBase:
|
|
"""
|
|
Get file external link endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to get the external link for.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file external link.
|
|
"""
|
|
pass
|
|
|
|
@file_router.post(
|
|
path='/archive',
|
|
summary='打包要下载的文件',
|
|
description='Archive files for download endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_archive(id: str) -> ResponseBase:
|
|
"""
|
|
Archive files for download endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to archive.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the archived files.
|
|
"""
|
|
pass
|
|
|
|
@file_router.post(
|
|
path='/compress',
|
|
summary='创建文件压缩任务',
|
|
description='Create file compression task endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_compress(id: str) -> ResponseBase:
|
|
"""
|
|
Create file compression task endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to compress.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file compression task.
|
|
"""
|
|
pass
|
|
|
|
@file_router.post(
|
|
path='/decompress',
|
|
summary='创建文件解压任务',
|
|
description='Create file extraction task endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_decompress(id: str) -> ResponseBase:
|
|
"""
|
|
Create file extraction task endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to decompress.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file extraction task.
|
|
"""
|
|
pass
|
|
|
|
@file_router.post(
|
|
path='/relocate',
|
|
summary='创建文件转移任务',
|
|
description='Create file relocation task endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_relocate(id: str) -> ResponseBase:
|
|
"""
|
|
Create file relocation task endpoint.
|
|
|
|
Args:
|
|
id (str): The ID of the file to relocate.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file relocation task.
|
|
"""
|
|
pass
|
|
|
|
@file_router.get(
|
|
path='/search/{type}/{keyword}',
|
|
summary='搜索文件',
|
|
description='Search files by keyword endpoint.',
|
|
dependencies=[Depends(SignRequired)]
|
|
)
|
|
def router_file_search(type: str, keyword: str) -> ResponseBase:
|
|
"""
|
|
Search files by keyword endpoint.
|
|
|
|
Args:
|
|
type (str): The type of search (e.g., 'name', 'content').
|
|
keyword (str): The keyword to search for.
|
|
|
|
Returns:
|
|
ResponseModel: A model containing the response data for the file search.
|
|
"""
|
|
pass |