Move request handling

This commit is contained in:
2025-12-31 16:44:17 +01:00
parent 9d795c426e
commit 36526bfc86
2 changed files with 28 additions and 29 deletions

View File

@@ -1,3 +1,6 @@
import threading
import requests
from flask import jsonify, request
from services.game_service import GameService
@@ -45,9 +48,29 @@ class GameController:
if auth_token != "Bearer " + self.auth_token:
return jsonify({"status": "error", "message": "Invalid authorization token"}), 401
self._game_service.make_move()
img, fen = self._game_service.make_move()
threading.Thread(
target=self.__send_detection_result,
args=("https://192.168.15.125:1880/party/image", img, fen),
daemon=True
).start()
return jsonify({"status": "ok"}), 200
except Exception as ex:
print(ex)
return jsonify({"status": "error", "message": f"An error occurred : {ex}"}), 500
return jsonify({"status": "error", "message": f"An error occurred : {ex}"}), 500
def __send_detection_result(self, url, img, fen):
try:
headers = {'Content-Type': 'image/jpeg'}
body = {'frame': img, 'fen': fen}
response = requests.post(
url,
data=body,
headers=headers,
verify=False)
print(response.status_code)
except Exception as e:
print(e)