From 301ee923014b08cd4487f2c488184fd391fdaa72 Mon Sep 17 00:00:00 2001 From: Lan Date: Wed, 3 Jun 2026 04:58:19 +0800 Subject: [PATCH] feat: add admin file detail endpoint --- apps/admin/services.py | 65 ++++++++++++++++++++++++++++++++++++++++++ apps/admin/views.py | 18 ++++++++++++ 2 files changed, 83 insertions(+) diff --git a/apps/admin/services.py b/apps/admin/services.py index 9e1ad7c..1668bda 100644 --- a/apps/admin/services.py +++ b/apps/admin/services.py @@ -196,6 +196,71 @@ class FileService: ) return data + async def get_file_detail(self, file_id: int): + file_code = await FileCodes.filter(id=file_id).first() + if not file_code: + raise HTTPException(status_code=404, detail="文件不存在") + + detail = await self._build_admin_file_item(file_code) + is_text = file_code.text is not None + has_download_limit = file_code.expired_count >= 0 + is_permanent = file_code.expired_at is None and file_code.expired_count < 0 + text_length = len(file_code.text) if file_code.text else 0 + + detail.update( + { + "filename": detail["name"], + "displayName": detail["name"], + "display_name": detail["name"], + "isPermanent": is_permanent, + "is_permanent": is_permanent, + "hasDownloadLimit": has_download_limit, + "has_download_limit": has_download_limit, + "hasExpirationTime": file_code.expired_at is not None, + "has_expiration_time": file_code.expired_at is not None, + "textLength": text_length, + "text_length": text_length, + "canPreviewText": is_text, + "can_preview_text": is_text, + "canDownload": not is_text, + "can_download": not is_text, + "storageBackend": settings.file_storage, + "storage_backend": settings.file_storage, + "filePath": file_code.file_path, + "file_path": file_code.file_path, + "uuidFileName": file_code.uuid_file_name, + "uuid_file_name": file_code.uuid_file_name, + "uploadId": file_code.upload_id, + "upload_id": file_code.upload_id, + "policy": { + "expiredAt": file_code.expired_at, + "expired_at": file_code.expired_at, + "expiredCount": file_code.expired_count, + "expired_count": file_code.expired_count, + "remainingDownloads": detail["remainingDownloads"], + "remaining_downloads": detail["remaining_downloads"], + "isExpired": detail["isExpired"], + "is_expired": detail["is_expired"], + "isPermanent": is_permanent, + "is_permanent": is_permanent, + }, + "storage": { + "backend": settings.file_storage, + "filePath": file_code.file_path, + "file_path": file_code.file_path, + "uuidFileName": file_code.uuid_file_name, + "uuid_file_name": file_code.uuid_file_name, + "fileHash": file_code.file_hash, + "file_hash": file_code.file_hash, + "isChunked": file_code.is_chunked, + "is_chunked": file_code.is_chunked, + "uploadId": file_code.upload_id, + "upload_id": file_code.upload_id, + }, + } + ) + return detail + def _match_admin_file( self, item: dict[str, Any], diff --git a/apps/admin/views.py b/apps/admin/views.py index 14d5d14..011e634 100644 --- a/apps/admin/views.py +++ b/apps/admin/views.py @@ -251,6 +251,24 @@ async def file_list( ) +@admin_api.get("/file/detail") +async def file_detail( + id: int, + file_service: FileService = Depends(get_file_service), +): + detail = await file_service.get_file_detail(id) + return APIResponse(detail=detail) + + +@admin_api.post("/file/detail") +async def file_detail_post( + data: IDData, + file_service: FileService = Depends(get_file_service), +): + detail = await file_service.get_file_detail(data.id) + return APIResponse(detail=detail) + + @admin_api.get("/config/get") async def get_config( config_service: ConfigService = Depends(get_config_service),