|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import uuid
|
|
|
|
import uuid
|
|
|
|
from datetime import date, datetime
|
|
|
|
from datetime import date, datetime
|
|
|
@ -187,7 +188,9 @@ async def get_docx_stream(
|
|
|
|
|
|
|
|
|
|
|
|
# 记录到数据库
|
|
|
|
# 记录到数据库
|
|
|
|
await db.execute("UPDATE t_bi_question SET docx_file_name = $1 WHERE id = $2", filename, question_id)
|
|
|
|
await db.execute("UPDATE t_bi_question SET docx_file_name = $1 WHERE id = $2", filename, question_id)
|
|
|
|
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
|
|
|
|
# 客户端提前断开连接,无需处理
|
|
|
|
|
|
|
|
print("客户端断开连接")
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
# 如果发生异常,返回错误信息
|
|
|
|
# 如果发生异常,返回错误信息
|
|
|
|
error_response = json.dumps({
|
|
|
|
error_response = json.dumps({
|
|
|
@ -200,7 +203,7 @@ async def get_docx_stream(
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
# 确保资源释放
|
|
|
|
# 确保资源释放
|
|
|
|
if "response" in locals():
|
|
|
|
if "response" in locals():
|
|
|
|
await response.aclose()
|
|
|
|
await response.close()
|
|
|
|
|
|
|
|
|
|
|
|
# 使用 StreamingResponse 返回流式结果
|
|
|
|
# 使用 StreamingResponse 返回流式结果
|
|
|
|
return StreamingResponse(
|
|
|
|
return StreamingResponse(
|
|
|
|