108 lines
2.7 KiB
Python
108 lines
2.7 KiB
Python
"""
|
|
数据汇交上传 API
|
|
"""
|
|
from typing import Optional
|
|
from fastapi import APIRouter, UploadFile, File, Form, HTTPException, BackgroundTasks
|
|
from app.core.security import verify_upload_key
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/verify-key")
|
|
async def verify_key(key: str = Form(...)):
|
|
"""
|
|
验证上传口令
|
|
"""
|
|
is_valid = await verify_upload_key(key)
|
|
if not is_valid:
|
|
raise HTTPException(status_code=401, detail="Invalid upload key")
|
|
return {"status": "success", "message": "Key verified"}
|
|
|
|
|
|
@router.post("/genome")
|
|
async def upload_genome_data(
|
|
background_tasks: BackgroundTasks,
|
|
project_id: str = Form(...),
|
|
submitter_name: str = Form(...),
|
|
submitter_email: str = Form(...),
|
|
upload_key: str = Form(...),
|
|
file: Optional[UploadFile] = File(None),
|
|
):
|
|
"""
|
|
上传基因组数据
|
|
|
|
支持逐条提交和批量上传
|
|
"""
|
|
# 验证口令
|
|
if not await verify_upload_key(upload_key):
|
|
raise HTTPException(status_code=401, detail="Invalid upload key")
|
|
|
|
# TODO: 处理文件上传
|
|
if file:
|
|
# 异步保存文件
|
|
filename = file.filename
|
|
# background_tasks.add_task(save_file, file, filename)
|
|
|
|
# TODO: 保存到数据库
|
|
return {
|
|
"status": "success",
|
|
"message": "Data uploaded successfully",
|
|
"project_id": project_id
|
|
}
|
|
|
|
|
|
@router.post("/metagenome")
|
|
async def upload_metagenome_data(
|
|
background_tasks: BackgroundTasks,
|
|
project_id: str = Form(...),
|
|
submitter_name: str = Form(...),
|
|
upload_key: str = Form(...),
|
|
file: Optional[UploadFile] = File(None),
|
|
):
|
|
"""
|
|
上传宏基因组数据
|
|
"""
|
|
if not await verify_upload_key(upload_key):
|
|
raise HTTPException(status_code=401, detail="Invalid upload key")
|
|
|
|
# TODO: 实现宏基因组数据上传逻辑
|
|
return {
|
|
"status": "success",
|
|
"message": "Metagenome data uploaded",
|
|
"project_id": project_id
|
|
}
|
|
|
|
|
|
@router.post("/raw-data")
|
|
async def upload_raw_data(
|
|
background_tasks: BackgroundTasks,
|
|
project_id: str = Form(...),
|
|
upload_key: str = Form(...),
|
|
file: UploadFile = File(...),
|
|
):
|
|
"""
|
|
上传原始测序数据
|
|
"""
|
|
if not await verify_upload_key(upload_key):
|
|
raise HTTPException(status_code=401, detail="Invalid upload key")
|
|
|
|
# TODO: 实现原始数据上传逻辑
|
|
return {
|
|
"status": "success",
|
|
"message": "Raw data uploaded",
|
|
"filename": file.filename
|
|
}
|
|
|
|
|
|
@router.get("/status/{upload_id}")
|
|
async def get_upload_status(upload_id: str):
|
|
"""
|
|
查询上传状态
|
|
"""
|
|
# TODO: 从数据库查询上传状态
|
|
return {
|
|
"upload_id": upload_id,
|
|
"status": "processing",
|
|
"progress": 50
|
|
}
|