Files
disknext/routers/api/v1/share/__init__.py
于小丘 abd85e2290 Refactor auth and unify error handling in routers
Renamed AuthRequired/AdminRequired to auth_required/admin_required and updated all references. Replaced direct HTTPException usage with utils.http_exceptions for consistent error handling. Updated router endpoints to use new auth dependency and standardized not implemented responses. Cleaned up unused theme fields in SiteConfigResponse and improved site config endpoint. Minor type and import cleanups across routers and middleware.
2025-12-25 19:08:46 +08:00

308 lines
8.0 KiB
Python

from fastapi import APIRouter, Depends
from middleware.auth import auth_required
from models import ResponseBase
from utils import http_exceptions
share_router = APIRouter(
prefix='/share',
tags=["share"],
)
@share_router.get(
path='/{info}/{id}',
summary='获取分享',
description='Get shared content by info type and ID.',
)
def router_share_get(info: str, id: str) -> ResponseBase:
"""
Get shared content by info type and ID.
Args:
info (str): The type of information being shared.
id (str): The ID of the shared content.
Returns:
dict: A dictionary containing shared content information.
"""
http_exceptions.raise_not_implemented()
@share_router.put(
path='/download/{id}',
summary='创建文件下载会话',
description='Create a file download session by ID.',
)
def router_share_download(id: str) -> ResponseBase:
"""
Create a file download session by ID.
Args:
id (str): The ID of the file to be downloaded.
Returns:
dict: A dictionary containing download session information.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='preview/{id}',
summary='预览分享文件',
description='Preview shared file by ID.',
)
def router_share_preview(id: str) -> ResponseBase:
"""
Preview shared file by ID.
Args:
id (str): The ID of the file to be previewed.
Returns:
dict: A dictionary containing preview information.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/doc/{id}',
summary='取得Office文档预览地址',
description='Get Office document preview URL by ID.',
)
def router_share_doc(id: str) -> ResponseBase:
"""
Get Office document preview URL by ID.
Args:
id (str): The ID of the Office document.
Returns:
dict: A dictionary containing the document preview URL.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/content/{id}',
summary='获取文本文件内容',
description='Get text file content by ID.',
)
def router_share_content(id: str) -> ResponseBase:
"""
Get text file content by ID.
Args:
id (str): The ID of the text file.
Returns:
str: The content of the text file.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/list/{id}/{path:path}',
summary='获取目录列文件',
description='Get directory listing by ID and path.',
)
def router_share_list(id: str, path: str = '') -> ResponseBase:
"""
Get directory listing by ID and path.
Args:
id (str): The ID of the directory.
path (str): The path within the directory.
Returns:
dict: A dictionary containing directory listing information.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/search/{id}/{type}/{keywords}',
summary='分享目录搜索',
description='Search within a shared directory by ID, type, and keywords.',
)
def router_share_search(id: str, type: str, keywords: str) -> ResponseBase:
"""
Search within a shared directory by ID, type, and keywords.
Args:
id (str): The ID of the shared directory.
type (str): The type of search (e.g., file, folder).
keywords (str): The keywords to search for.
Returns:
dict: A dictionary containing search results.
"""
http_exceptions.raise_not_implemented()
@share_router.post(
path='/archive/{id}',
summary='归档打包下载',
description='Archive and download shared content by ID.',
)
def router_share_archive(id: str) -> ResponseBase:
"""
Archive and download shared content by ID.
Args:
id (str): The ID of the content to be archived.
Returns:
dict: A dictionary containing archive download information.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/readme/{id}',
summary='获取README文本文件内容',
description='Get README text file content by ID.',
)
def router_share_readme(id: str) -> ResponseBase:
"""
Get README text file content by ID.
Args:
id (str): The ID of the README file.
Returns:
str: The content of the README file.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/thumb/{id}/{file}',
summary='获取缩略图',
description='Get thumbnail image by ID and file name.',
)
def router_share_thumb(id: str, file: str) -> ResponseBase:
"""
Get thumbnail image by ID and file name.
Args:
id (str): The ID of the shared content.
file (str): The name of the file for which to get the thumbnail.
Returns:
str: A Base64 encoded string of the thumbnail image.
"""
http_exceptions.raise_not_implemented()
@share_router.post(
path='/report/{id}',
summary='举报分享',
description='Report shared content by ID.',
)
def router_share_report(id: str) -> ResponseBase:
"""
Report shared content by ID.
Args:
id (str): The ID of the shared content to report.
Returns:
dict: A dictionary containing report submission information.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/search',
summary='搜索公共分享',
description='Search public shares by keywords and type.',
)
def router_share_search_public(keywords: str, type: str = 'all') -> ResponseBase:
"""
Search public shares by keywords and type.
Args:
keywords (str): The keywords to search for.
type (str): The type of search (e.g., all, file, folder).
Returns:
dict: A dictionary containing search results for public shares.
"""
http_exceptions.raise_not_implemented()
#####################
# 需要登录的接口
#####################
@share_router.post(
path='/',
summary='创建新分享',
description='Create a new share endpoint.',
dependencies=[Depends(auth_required)]
)
def router_share_create() -> ResponseBase:
"""
Create a new share endpoint.
Returns:
ResponseBase: A model containing the response data for the new share creation.
"""
http_exceptions.raise_not_implemented()
@share_router.get(
path='/',
summary='列出我的分享',
description='Get a list of shares.',
dependencies=[Depends(auth_required)]
)
def router_share_list() -> ResponseBase:
"""
Get a list of shares.
Returns:
ResponseBase: A model containing the response data for the list of shares.
"""
http_exceptions.raise_not_implemented()
@share_router.post(
path='/save/{id}',
summary='转存他人分享',
description='Save another user\'s share by ID.',
dependencies=[Depends(auth_required)]
)
def router_share_save(id: str) -> ResponseBase:
"""
Save another user's share by ID.
Args:
id (str): The ID of the share to be saved.
Returns:
ResponseBase: A model containing the response data for the saved share.
"""
http_exceptions.raise_not_implemented()
@share_router.patch(
path='/{id}',
summary='更新分享信息',
description='Update share information by ID.',
dependencies=[Depends(auth_required)]
)
def router_share_update(id: str) -> ResponseBase:
"""
Update share information by ID.
Args:
id (str): The ID of the share to be updated.
Returns:
ResponseBase: A model containing the response data for the updated share.
"""
http_exceptions.raise_not_implemented()
@share_router.delete(
path='/{id}',
summary='删除分享',
description='Delete a share by ID.',
dependencies=[Depends(auth_required)]
)
def router_share_delete(id: str) -> ResponseBase:
"""
Delete a share by ID.
Args:
id (str): The ID of the share to be deleted.
Returns:
ResponseBase: A model containing the response data for the deleted share.
"""
http_exceptions.raise_not_implemented()