zhangxiao
2024-10-23 7cb75dd91c03c3261be18d227e40d5eab1660628
修改返回内容
1个文件已修改
32 ■■■■ 已修改文件
app/api/excel.py 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/excel.py
@@ -79,17 +79,37 @@
    while True:
        data = await websocket.receive_text()
        try:
            if data == "合并Excel文件":
            if data == "\"合并Excel\"":
                clear_directory(EXCEL_FILES_PATH)
                output_file_path = run_conformity()
                await websocket.send_json({"step_message": "开始合并", "type": "stream", "files": []})
            elif data == "查询合并进度":
                clear_directory(EXCEL_FILES_PATH)
                output_file_path = run_conformity()
                files = os.listdir(EXCEL_FILES_PATH)
                if files:
                    first_file = files[0]
                    file_name = os.path.basename(first_file)
                    file_url = f"./api/document/download/{first_file}"
                    await websocket.send_json({
                        "step_message": "文档合并成功!",
                        "type": "stream",
                        "files": [{
                            "file_name": file_name,
                            "file_url": file_url
                        }]
                    })
                    await websocket.send_json({
                        "step_message": "",
                        "type": "close",
                    })
                else:
                    await websocket.send_json({"error": "合并操作未生成文件", "type": "stream", "files": []})
            elif data == "\"查询合并进度\"":
                files = os.listdir(EXCEL_FILES_PATH)
                if not files:
                    await websocket.send_json({"step_message": "正在合并中", "type": "stream", "files": []})
                else:
                    await websocket.send_json({"step_message": "文档合并成功!", "type": "stream", "files": []})
            elif data == "获取文件":
            elif data == "\"获取文件\"":
                files = os.listdir(EXCEL_FILES_PATH)
                if not files:
                    await websocket.send_json({"error": "目录下没有生成的文件", "type": "stream", "files": []})
@@ -106,9 +126,11 @@
                        }]
                    })
            else:
                await websocket.send_json({"error": "未知指令"})
                print(f"Received data: {data}")
                await websocket.send_json({"error": "未知指令", "data": str(data)})
        except Exception as e:
            await websocket.send_json({"error": str(e)})
            await websocket.close()
@router.get("/download/{filename}")