| | |
| | | import random |
| | | import string |
| | | |
| | | from fastapi import APIRouter, File, UploadFile, Form, BackgroundTasks, Depends |
| | | from fastapi import APIRouter, File, UploadFile, Form, BackgroundTasks, Depends, Request |
| | | from fastapi.responses import JSONResponse, FileResponse |
| | | from sqlalchemy.orm import Session |
| | | from starlette.websockets import WebSocket |
| | |
| | | if session: |
| | | session_id = session.id |
| | | new_message = { |
| | | "role": "user", |
| | | "download_url": f"./api/document/download/{merge_file}.xlsx" |
| | | "role": "assistant", |
| | | "content": { |
| | | "message": "\u5408\u5e76\u6210\u529f", |
| | | "type": "message", |
| | | "file_url": f"/api/document/download/{merge_file}.xlsx", |
| | | "file_name": f"{merge_file}.xlsx" |
| | | } |
| | | } |
| | | session_service = SessionService(db) |
| | | session_service.update_session(session_id, message=new_message) |
| | |
| | | |
| | | |
| | | @router.get("/download/{file_full_name}") |
| | | async def download_file(background_tasks: BackgroundTasks, file_full_name: str): |
| | | async def download_file(file_full_name: str): |
| | | file_name = os.path.basename(file_full_name) |
| | | user_excel = EXCEL_FILES_PATH |
| | | file_path = os.path.join(user_excel, file_full_name) |
| | | |
| | | if not os.path.exists(file_path): |
| | | return JSONResponse(content={"error": "文件不存在"}, status_code=404) |
| | | |
| | | return FileResponse( |
| | | path=file_path, |
| | | filename="Excel.xlsx", |
| | | media_type='application/octet-stream', |
| | | ) |
| | | # def delete_file(): |
| | | # try: |
| | | # os.unlink(file_path) |