feat: 新增 pdf_translate 命令行工具
- 支持命令: translate/list/status/download/config - 支持用户认证: --user --password 参数 - 翻译进度实时显示,结果可在网页查看 - 新增 /api/config 和 /api/translations 接口 - 修复异步翻译任务的配置获取逻辑
This commit is contained in:
36
app.py
36
app.py
@@ -445,6 +445,36 @@ def upload_pdf():
|
||||
})
|
||||
|
||||
|
||||
@app.route('/api/config')
|
||||
def api_config():
|
||||
"""获取系统配置"""
|
||||
from admin import get_llm_config, get_site_config
|
||||
|
||||
return jsonify({
|
||||
'site_name': get_site_config().get('site_name'),
|
||||
'max_file_size': get_site_config().get('max_file_size'),
|
||||
'cache_expire_days': get_site_config().get('cache_expire_days'),
|
||||
'llm_config': get_llm_config()
|
||||
})
|
||||
|
||||
|
||||
@app.route('/api/translations')
|
||||
def api_translations_list():
|
||||
"""获取翻译记录列表"""
|
||||
user = get_current_user()
|
||||
|
||||
if user:
|
||||
translations = Translation.query.filter_by(user_id=user.id)\
|
||||
.order_by(Translation.created_at.desc()).limit(20).all()
|
||||
else:
|
||||
# 访客返回空列表
|
||||
translations = []
|
||||
|
||||
return jsonify({
|
||||
'translations': [t.to_dict() for t in translations]
|
||||
})
|
||||
|
||||
|
||||
@app.route('/api/status/<int:translation_id>')
|
||||
def translation_status(translation_id):
|
||||
"""获取翻译状态"""
|
||||
@@ -462,8 +492,12 @@ def translation_status(translation_id):
|
||||
'id': translation.id,
|
||||
'status': translation.status,
|
||||
'progress': translation.progress,
|
||||
'filename': translation.original_filename,
|
||||
'pages': translation.page_count,
|
||||
'from_cache': translation.from_cache,
|
||||
'error': translation.error_message
|
||||
'error': translation.error_message,
|
||||
'created_at': translation.created_at.isoformat() if translation.created_at else None,
|
||||
'completed_at': translation.completed_at.isoformat() if translation.completed_at else None,
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user