fix
This commit is contained in:
@@ -70,7 +70,7 @@ def get_towns():
|
|||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# GET /dashboard/client-status
|
# GET /dashboard/client-status
|
||||||
# Returns whether the Tampermonkey client is considered online.
|
# Returns whether the Tampermonkey client is considered online.
|
||||||
# Online = at least one town_state row updated within the last 60 s.
|
# Online = at least one town_state row updated within the last 150 s.
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@dashboard.route('/dashboard/client-status', methods=['GET'])
|
@dashboard.route('/dashboard/client-status', methods=['GET'])
|
||||||
def client_status():
|
def client_status():
|
||||||
@@ -85,7 +85,7 @@ def client_status():
|
|||||||
try:
|
try:
|
||||||
dt = datetime.fromisoformat(last_seen)
|
dt = datetime.fromisoformat(last_seen)
|
||||||
age_s = (datetime.utcnow() - dt).total_seconds()
|
age_s = (datetime.utcnow() - dt).total_seconds()
|
||||||
online = age_s <= 60
|
online = age_s <= 150
|
||||||
except Exception:
|
except Exception:
|
||||||
online = False
|
online = False
|
||||||
else:
|
else:
|
||||||
@@ -132,7 +132,7 @@ def create_command():
|
|||||||
if cmd_type not in ('build', 'recruit'):
|
if cmd_type not in ('build', 'recruit'):
|
||||||
return jsonify({'error': 'type must be build or recruit'}), 400
|
return jsonify({'error': 'type must be build or recruit'}), 400
|
||||||
|
|
||||||
# Reject if the Tampermonkey client is offline (no state push in last 60 s)
|
# Reject if the Tampermonkey client is offline (no state push in last 150 s)
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
row = conn.execute('SELECT MAX(updated_at) AS last_seen FROM town_state').fetchone()
|
row = conn.execute('SELECT MAX(updated_at) AS last_seen FROM town_state').fetchone()
|
||||||
last_seen = row['last_seen'] if row else None
|
last_seen = row['last_seen'] if row else None
|
||||||
@@ -140,7 +140,7 @@ def create_command():
|
|||||||
if last_seen:
|
if last_seen:
|
||||||
try:
|
try:
|
||||||
dt = datetime.fromisoformat(last_seen)
|
dt = datetime.fromisoformat(last_seen)
|
||||||
client_online = (datetime.utcnow() - dt).total_seconds() <= 60
|
client_online = (datetime.utcnow() - dt).total_seconds() <= 150
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user