diff --git a/src/api/routes.py b/src/api/routes.py index 52739ec..4b8a47c 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -33,6 +33,7 @@ tasks = {} @router.get("/") +@router.post("/") async def read_root(request: Request): """主页面""" from fastapi.templating import Jinja2Templates @@ -48,6 +49,7 @@ async def read_root(request: Request): @router.get("/health") +@router.post("/health") async def health(): return { "status": "healthy", @@ -113,6 +115,7 @@ async def upload_stp( @router.get("/status/{task_id}") +@router.post("/status/{task_id}") async def get_status(task_id: str): """获取任务状态""" if task_id not in tasks: @@ -124,6 +127,7 @@ async def get_status(task_id: str): @router.get("/debug/tasks") +@router.post("/debug/tasks") async def debug_tasks(): """调试接口:查看所有任务""" return { @@ -133,6 +137,7 @@ async def debug_tasks(): @router.get("/api/history") +@router.post("/api/history") async def get_file_history(): """获取按文件名分组的文件历史记录""" # 按文件名分组 @@ -166,6 +171,7 @@ async def get_file_history(): @router.get("/api/history/{filename}") +@router.post("/api/history/{filename}") async def get_file_records(filename: str): """获取指定文件名的所有记录""" # URL解码文件名 @@ -194,6 +200,7 @@ async def get_file_records(filename: str): @router.get("/history") +@router.post("/history") async def history_page(request: Request): """历史记录页面""" from fastapi.templating import Jinja2Templates @@ -209,6 +216,7 @@ async def history_page(request: Request): @router.get("/result/{task_id}") +@router.post("/result/{task_id}") async def result_page(request: Request, task_id: str): """结果详情页面""" if task_id not in tasks: diff --git a/src/main.py b/src/main.py index 5b8b6d8..97b7753 100644 --- a/src/main.py +++ b/src/main.py @@ -101,6 +101,7 @@ app.include_router(router) @app.get("/health") +@app.post("/health") async def health(): from database.database import db_manager return { diff --git a/static/history.js b/static/history.js index c1430b5..0b8dc3c 100644 --- a/static/history.js +++ b/static/history.js @@ -9,7 +9,9 @@ async function loadHistory() { const fileList = document.getElementById('fileList'); try { - const response = await fetch('/api/history'); + const response = await fetch('/api/history', { + method: 'POST' + }); if (!response.ok) { throw new Error('获取历史记录失败'); } @@ -94,7 +96,9 @@ async function toggleFileRecords(filename) { } try { - const response = await fetch(`/api/history/${encodeURIComponent(filename)}`); + const response = await fetch(`/api/history/${encodeURIComponent(filename)}`, { + method: 'POST' + }); if (!response.ok) { throw new Error('获取记录详情失败'); } diff --git a/static/script.js b/static/script.js index 2a1ba38..85a9d55 100644 --- a/static/script.js +++ b/static/script.js @@ -143,7 +143,9 @@ async function uploadFile() { async function pollTaskStatus(taskId) { try { - const response = await fetch(`/status/${taskId}`); + const response = await fetch(`/status/${taskId}`, { + method: 'POST' + }); const task = await response.json(); console.log('任务状态:', task.status); @@ -566,6 +568,29 @@ function hideError() { errorMessage.style.display = 'none'; } +// 通过POST请求跳转到历史页面 +async function goToHistory() { + try { + const response = await fetch('/history', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + } + }); + + if (response.ok) { + // 如果返回的是HTML页面,直接重定向 + window.location.href = '/history'; + } else { + throw new Error('跳转失败'); + } + } catch (error) { + console.error('跳转到历史页面失败:', error); + // 如果POST失败,尝试直接GET跳转 + window.location.href = '/history'; + } +} + // 添加显示函数 function displayCavityData(cavityData) { const cavityDiv = document.getElementById('cavityData'); diff --git a/templates/index.html b/templates/index.html index bce1006..5d22766 100644 --- a/templates/index.html +++ b/templates/index.html @@ -117,7 +117,7 @@
PythonOCC 可用: {{ pythonocc_available }} | 服务版本: 3.0.0