fix(app): Add main logic for queue

This commit is contained in:
Black_Raven committed 2026-10-07 14:32:47 +03:00
1 parent af97cae9d8
commit 85964d002f
1 file changed
+33
+33
View File
@@ -56,6 +56,39 @@ def ai_request():
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route("/AI/<string:id>", methods=["GET"])
def req_status(id):
try:
with sqlite3.connect(DB_PATH) as conn:
row = conn.execute(
"SELECT status, result FROM requests WHERE id = ?", (id,)
).fetchone()
except Exception as e:
return jsonify({"error": str(e)}), 500
if row is None:
return jsonify({"error": f"task {id} not found"}), 404
status, result = row
if status not in ("OK", "ОК"):
return jsonify({"id": id, "status": status}), 200
if not result:
return jsonify({"error": f"task {id} is OK but has no result file"}), 500
path = Path(result)
if not path.is_absolute():
path = RESULT_DIR / path
if not path.is_file():
return jsonify({"error": f"result file not found: {path}"}), 404
try:
return send_file(path, as_attachment=True, download_name=path.name)
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/health', methods=['GET'])
def health_check():
"""Проверка работоспособности API"""