fix: 修复时区问题和翻译状态更新问题
- 使用上海时区(UTC+8)判断每日次数重置,而不是UTC时间 - 翻译任务完成后更新数据库Translation记录的状态和进度 - 传入translation_id和app到TranslationTask以支持数据库状态同步
This commit is contained in:
21
app.py
21
app.py
@@ -229,13 +229,8 @@ def upload_pdf():
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = os.path.join(output_dir, f"{filename}_translated.md")
|
||||
|
||||
# 创建异步翻译任务
|
||||
# 创建异步翻译任务(先不创建,等translation_id生成后)
|
||||
task_id = str(uuid.uuid4())
|
||||
TranslationTask.create_task(
|
||||
task_id, upload_path, output_path,
|
||||
{'LLM_CONFIG': LLM_CONFIG},
|
||||
instruction
|
||||
)
|
||||
|
||||
# 创建翻译记录
|
||||
translation = Translation(
|
||||
@@ -252,6 +247,20 @@ def upload_pdf():
|
||||
)
|
||||
db.session.add(translation)
|
||||
|
||||
# 预先提交获取 translation_id
|
||||
if not from_cache:
|
||||
db.session.flush() # 获取 ID 但不提交完整事务
|
||||
|
||||
# 创建异步翻译任务(需要翻译时)
|
||||
if not from_cache:
|
||||
TranslationTask.create_task(
|
||||
task_id, upload_path, output_path,
|
||||
{'LLM_CONFIG': LLM_CONFIG},
|
||||
instruction,
|
||||
translation_id=translation.id,
|
||||
app=app
|
||||
)
|
||||
|
||||
# 更新用户/访客计数
|
||||
if user:
|
||||
user.increment_count()
|
||||
|
||||
Reference in New Issue
Block a user