完成部分API路由以及文档
This commit is contained in:
381
routers/controllers/file.py
Normal file
381
routers/controllers/file.py
Normal file
@@ -0,0 +1,381 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from middleware.auth import SignRequired
|
||||
from models.response import ResponseModel
|
||||
|
||||
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) -> ResponseModel:
|
||||
"""
|
||||
Get file external link 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.
|
||||
"""
|
||||
...
|
||||
|
||||
@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) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_upload_router.get(
|
||||
path='/download/{id}',
|
||||
summary='下载文件',
|
||||
description='Download file endpoint.',
|
||||
)
|
||||
def router_file_download(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_upload_router.get(
|
||||
path='/archive/{sessionID}/archive.zip',
|
||||
summary='打包并下载文件',
|
||||
description='Archive and download files endpoint.',
|
||||
)
|
||||
def router_file_archive_download(sessionID: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_upload_router.post(
|
||||
path='/{sessionID}/{index}',
|
||||
summary='文件上传',
|
||||
description='File upload endpoint.',
|
||||
)
|
||||
def router_file_upload(sessionID: str, index: int) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_upload_router.put(
|
||||
path='/',
|
||||
summary='创建上传会话',
|
||||
description='Create an upload session endpoint.',
|
||||
dependencies=[Depends(SignRequired)],
|
||||
)
|
||||
def router_file_upload_session() -> ResponseModel:
|
||||
"""
|
||||
Create an upload session endpoint.
|
||||
|
||||
Returns:
|
||||
ResponseModel: A model containing the response data for the upload session.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_upload_router.delete(
|
||||
path='/{sessionID}',
|
||||
summary='删除上传会话',
|
||||
description='Delete an upload session endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_upload_session_delete(sessionID: str) -> ResponseModel:
|
||||
"""
|
||||
Delete an upload session endpoint.
|
||||
|
||||
Args:
|
||||
sessionID (str): The session ID to delete.
|
||||
|
||||
Returns:
|
||||
ResponseModel: A model containing the response data for the deletion.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_upload_router.delete(
|
||||
path='/',
|
||||
summary='清除所有上传会话',
|
||||
description='Clear all upload sessions endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_upload_session_clear() -> ResponseModel:
|
||||
"""
|
||||
Clear all upload sessions endpoint.
|
||||
|
||||
Returns:
|
||||
ResponseModel: A model containing the response data for clearing all sessions.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.put(
|
||||
path='/update/{id}',
|
||||
summary='更新文件',
|
||||
description='Update file information endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_update(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.post(
|
||||
path='/create',
|
||||
summary='创建空白文件',
|
||||
description='Create a blank file endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_create() -> ResponseModel:
|
||||
"""
|
||||
Create a blank file endpoint.
|
||||
|
||||
Returns:
|
||||
ResponseModel: A model containing the response data for the file creation.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.put(
|
||||
path='/download/{id}',
|
||||
summary='创建文件下载会话',
|
||||
description='Create a file download session endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_download(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.get(
|
||||
path='/preview/{id}',
|
||||
summary='预览文件',
|
||||
description='Preview file endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_preview(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.get(
|
||||
path='/content/{id}',
|
||||
summary='获取文本文件内容',
|
||||
description='Get text file content endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_content(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.get(
|
||||
path='/doc/{id}',
|
||||
summary='获取Office文档预览地址',
|
||||
description='Get Office document preview URL endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_doc(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.get(
|
||||
path='/thumb/{id}',
|
||||
summary='获取文件缩略图',
|
||||
description='Get file thumbnail endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_thumb(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.post(
|
||||
path='/source/{id}',
|
||||
summary='取得文件外链',
|
||||
description='Get file external link endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_source(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.post(
|
||||
path='/archive',
|
||||
summary='打包要下载的文件',
|
||||
description='Archive files for download endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_archive(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.post(
|
||||
path='/compress',
|
||||
summary='创建文件压缩任务',
|
||||
description='Create file compression task endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_compress(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.post(
|
||||
path='/decompress',
|
||||
summary='创建文件解压任务',
|
||||
description='Create file extraction task endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_decompress(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@file_router.post(
|
||||
path='/relocate',
|
||||
summary='创建文件转移任务',
|
||||
description='Create file relocation task endpoint.',
|
||||
dependencies=[Depends(SignRequired)]
|
||||
)
|
||||
def router_file_relocate(id: str) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
|
||||
@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) -> ResponseModel:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
...
|
||||
Reference in New Issue
Block a user