[ZILANT] коррекция работы фронта с долгим ответом ИИ
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
+17
-3
@@ -1011,12 +1011,23 @@ def api_generate_shortname(post_id):
|
||||
try:
|
||||
post = db.get_post(post_id)
|
||||
if not post:
|
||||
return jsonify({'error': 'Post not found'}), 404
|
||||
return jsonify({'success': False, 'error': 'Post not found'}), 404
|
||||
|
||||
log_event(f"Генерация названия для поста ID: {post_id}")
|
||||
shortname = generate_ai_shortname(post['text'])
|
||||
if not shortname:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Не удалось сгенерировать название (пустой ответ AI)',
|
||||
}), 500
|
||||
|
||||
# После долгого AI-запроса MySQL-соединение могло протухнуть
|
||||
try:
|
||||
db.conn.ping(reconnect=True)
|
||||
except Exception:
|
||||
db.close()
|
||||
db = get_db()
|
||||
|
||||
# Обновляем shortname в базе данных
|
||||
with db.conn.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"UPDATE posts SET shortname = %s WHERE id = %s",
|
||||
@@ -1031,7 +1042,10 @@ def api_generate_shortname(post_id):
|
||||
log_event(error_msg)
|
||||
return jsonify({'success': False, 'error': error_msg}), 500
|
||||
finally:
|
||||
db.close()
|
||||
try:
|
||||
db.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@bp.route('/api/publish_post/<int:post_id>', methods=['POST'])
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user