Format code
This commit is contained in:
8
main.py
8
main.py
@@ -14,6 +14,8 @@ auto_stop_timer = None # Timer for automatic VNC stop
|
|||||||
|
|
||||||
@app.route('/cast', methods=['POST'])
|
@app.route('/cast', methods=['POST'])
|
||||||
def cast_spell():
|
def cast_spell():
|
||||||
|
global auto_stop_timer, LAST_CAST_ADDRESS
|
||||||
|
|
||||||
ip_address = request.form.get('ip_address')
|
ip_address = request.form.get('ip_address')
|
||||||
logging.info(f"Received POST request on /cast. Requested ip_address: {ip_address}")
|
logging.info(f"Received POST request on /cast. Requested ip_address: {ip_address}")
|
||||||
|
|
||||||
@@ -21,12 +23,11 @@ def cast_spell():
|
|||||||
logging.warning(f"Invalid or missing ip_address parameter: {ip_address}")
|
logging.warning(f"Invalid or missing ip_address parameter: {ip_address}")
|
||||||
return f"Invalid or missing 'ip_address' parameter.", 400
|
return f"Invalid or missing 'ip_address' parameter.", 400
|
||||||
|
|
||||||
global auto_stop_timer, LAST_CAST_ADDRESS
|
|
||||||
|
|
||||||
logging.info(f"Casting to {ip_address}.")
|
logging.info(f"Casting to {ip_address}.")
|
||||||
kill_vnc() # Kill any existing VNC session first
|
kill_vnc() # Kill any existing VNC session first
|
||||||
cast_machine(ip_address)
|
cast_machine(ip_address)
|
||||||
LAST_CAST_ADDRESS = ip_address
|
LAST_CAST_ADDRESS = ip_address
|
||||||
|
|
||||||
# Restart auto-stop timer
|
# Restart auto-stop timer
|
||||||
if auto_stop_timer is not None and auto_stop_timer.is_alive():
|
if auto_stop_timer is not None and auto_stop_timer.is_alive():
|
||||||
auto_stop_timer.cancel()
|
auto_stop_timer.cancel()
|
||||||
@@ -34,11 +35,13 @@ def cast_spell():
|
|||||||
auto_stop_timer = threading.Timer(AUTO_STOP_TIMEOUT_SECONDS, _auto_stop_vnc)
|
auto_stop_timer = threading.Timer(AUTO_STOP_TIMEOUT_SECONDS, _auto_stop_vnc)
|
||||||
auto_stop_timer.start()
|
auto_stop_timer.start()
|
||||||
logging.info(f"Scheduled auto-stop for VNC in {AUTO_STOP_TIMEOUT_SECONDS} seconds.")
|
logging.info(f"Scheduled auto-stop for VNC in {AUTO_STOP_TIMEOUT_SECONDS} seconds.")
|
||||||
|
|
||||||
return f"Successfully cast to {ip_address}.", 200
|
return f"Successfully cast to {ip_address}.", 200
|
||||||
|
|
||||||
@app.route('/stop', methods=['POST'])
|
@app.route('/stop', methods=['POST'])
|
||||||
def stop_cast():
|
def stop_cast():
|
||||||
global auto_stop_timer, LAST_CAST_ADDRESS
|
global auto_stop_timer, LAST_CAST_ADDRESS
|
||||||
|
|
||||||
ip_address = request.form.get('ip_address')
|
ip_address = request.form.get('ip_address')
|
||||||
logging.info(f"Received POST request on /stop for ip_address: {ip_address}")
|
logging.info(f"Received POST request on /stop for ip_address: {ip_address}")
|
||||||
|
|
||||||
@@ -57,6 +60,7 @@ def stop_cast():
|
|||||||
|
|
||||||
kill_vnc()
|
kill_vnc()
|
||||||
LAST_CAST_ADDRESS = None
|
LAST_CAST_ADDRESS = None
|
||||||
|
|
||||||
return "Attempted to stop VNC viewers.", 200
|
return "Attempted to stop VNC viewers.", 200
|
||||||
|
|
||||||
def _auto_stop_vnc():
|
def _auto_stop_vnc():
|
||||||
|
|||||||
Reference in New Issue
Block a user