commit
38e34219d3
16
app.py
16
app.py
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import os
|
||||||
import threading
|
import threading
|
||||||
import tomllib
|
import tomllib
|
||||||
import uuid
|
import uuid
|
||||||
@ -10,7 +11,12 @@ from pathlib import Path
|
|||||||
|
|
||||||
from fastapi import Body, FastAPI, HTTPException, Request
|
from fastapi import Body, FastAPI, HTTPException, Request
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
|
from fastapi.responses import (
|
||||||
|
FileResponse,
|
||||||
|
HTMLResponse,
|
||||||
|
JSONResponse,
|
||||||
|
StreamingResponse,
|
||||||
|
)
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
@ -93,6 +99,14 @@ async def index(request: Request):
|
|||||||
return templates.TemplateResponse("index.html", {"request": request})
|
return templates.TemplateResponse("index.html", {"request": request})
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/download")
|
||||||
|
async def download_file(file_path: str):
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
raise HTTPException(status_code=404, detail="File not found")
|
||||||
|
|
||||||
|
return FileResponse(file_path, filename=os.path.basename(file_path))
|
||||||
|
|
||||||
|
|
||||||
@app.post("/tasks")
|
@app.post("/tasks")
|
||||||
async def create_task(prompt: str = Body(..., embed=True)):
|
async def create_task(prompt: str = Body(..., embed=True)):
|
||||||
task = task_manager.create_task(prompt)
|
task = task_manager.create_task(prompt)
|
||||||
|
2
run.bat
2
run.bat
@ -6,7 +6,7 @@ set "VENV_DIR=%~dp0venv"
|
|||||||
set "PYTHON_PATH=%VENV_DIR%\python.exe"
|
set "PYTHON_PATH=%VENV_DIR%\python.exe"
|
||||||
|
|
||||||
where git >nul 2>&1
|
where git >nul 2>&1
|
||||||
if !errorlevel! == 0 (
|
if %errorlevel% == 0 (
|
||||||
echo Trying to sync with GitHub repository...
|
echo Trying to sync with GitHub repository...
|
||||||
git pull origin front-end 2>&1 || echo Failed to sync with GitHub, skipping update...
|
git pull origin front-end 2>&1 || echo Failed to sync with GitHub, skipping update...
|
||||||
) else (
|
) else (
|
||||||
|
@ -286,27 +286,27 @@ function createStepElement(type, content, timestamp) {
|
|||||||
fileInteractionHtml = `
|
fileInteractionHtml = `
|
||||||
<div class="file-interaction image-preview">
|
<div class="file-interaction image-preview">
|
||||||
<img src="${filePath}" alt="${fileName}" class="preview-image" onclick="showFullImage('${filePath}')">
|
<img src="${filePath}" alt="${fileName}" class="preview-image" onclick="showFullImage('${filePath}')">
|
||||||
<a href="${filePath}" download="${fileName}" class="download-link">⬇️ 下载图片</a>
|
<a href="/download?file_path=${filePath}" download="${fileName}" class="download-link">⬇️ 下载图片</a>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} else if (['mp3', 'wav', 'ogg'].includes(fileExtension)) {
|
} else if (['mp3', 'wav', 'ogg'].includes(fileExtension)) {
|
||||||
fileInteractionHtml = `
|
fileInteractionHtml = `
|
||||||
<div class="file-interaction audio-player">
|
<div class="file-interaction audio-player">
|
||||||
<audio controls src="${filePath}"></audio>
|
<audio controls src="${filePath}"></audio>
|
||||||
<a href="${filePath}" download="${fileName}" class="download-link">⬇️ 下载音频</a>
|
<a href="/download?file_path=${filePath}" download="${fileName}" class="download-link">⬇️ 下载音频</a>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} else if (fileExtension === 'py') {
|
} else if (['html', 'js', 'py'].includes(fileExtension)) {
|
||||||
fileInteractionHtml = `
|
fileInteractionHtml = `
|
||||||
<div class="file-interaction code-file">
|
<div class="file-interaction code-file">
|
||||||
<button onclick="simulateRunPython('${filePath}')" class="run-button">▶️ 模拟运行</button>
|
<button onclick="simulateRunPython('${filePath}')" class="run-button">▶️ 模拟运行</button>
|
||||||
<a href="${filePath}" download="${fileName}" class="download-link">⬇️ 下载文件</a>
|
<a href="/download?file_path=${filePath}" download="${fileName}" class="download-link">⬇️ 下载文件</a>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
fileInteractionHtml = `
|
fileInteractionHtml = `
|
||||||
<div class="file-interaction">
|
<div class="file-interaction">
|
||||||
<a href="${filePath}" download="${fileName}" class="download-link">⬇️ 下载文件: ${fileName}</a>
|
<a href="/download?file_path=${filePath}" download="${fileName}" class="download-link">⬇️ 下载文件: ${fileName}</a>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user