From 26a716951542ad95424f6b2fc782b63bb1eecf62 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Wed, 7 Jan 2026 04:15:55 +0100 Subject: [PATCH] modified: app.py modified: templates/itemeditor_command_storage.html --- app.py | 10 +++++----- templates/itemeditor_command_storage.html | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 200beed..f9cea3d 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,7 @@ import os import json import uuid from pathlib import Path -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from threading import Lock from flask import Flask, render_template, jsonify, send_from_directory, request @@ -15,7 +15,7 @@ storage_lock = Lock() def cleanup_expired_commands(): """Remove expired commands from storage""" with storage_lock: - now = datetime.now() + now = datetime.now(timezone.utc) expired_keys = [key for key, value in command_storage.items() if datetime.fromisoformat(value['expires_at']) < now] for key in expired_keys: @@ -268,8 +268,8 @@ def store_command(): # Generate UUID command_uuid = str(uuid.uuid4()) - # Calculate expiry (30 minutes) - created_at = datetime.now() + # Calculate expiry (30 minutes) - use UTC + created_at = datetime.now(timezone.utc) expires_at = created_at + timedelta(minutes=30) # Store command @@ -307,7 +307,7 @@ def retrieve_command(command_uuid): return jsonify({'error': 'Command not found or expired'}), 404 # Check if expired - if datetime.fromisoformat(command_data['expires_at']) < datetime.now(): + if datetime.fromisoformat(command_data['expires_at']) < datetime.now(timezone.utc): with storage_lock: del command_storage[command_uuid] return jsonify({'error': 'Command expired'}), 410 diff --git a/templates/itemeditor_command_storage.html b/templates/itemeditor_command_storage.html index 63001f8..93c8409 100644 --- a/templates/itemeditor_command_storage.html +++ b/templates/itemeditor_command_storage.html @@ -547,25 +547,30 @@ function startCountdown(expiresAt) { const expiryTime = document.getElementById('expiryTime'); const endTime = new Date(expiresAt).getTime(); - // If expiry is in the past, show expired immediately - if (endTime < new Date().getTime()) { - expiryTime.innerHTML = 'Expired'; - return; - } - - const interval = setInterval(() => { + // Update countdown immediately + function updateCountdown() { const now = new Date().getTime(); const distance = endTime - now; if (distance < 0) { - clearInterval(interval); expiryTime.innerHTML = 'Expired'; - return; + return false; } const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((distance % (1000 * 60)) / 1000); expiryTime.textContent = `${minutes}m ${seconds}s`; + return true; + } + + // Update immediately + if (!updateCountdown()) return; + + // Then update every second + const interval = setInterval(() => { + if (!updateCountdown()) { + clearInterval(interval); + } }, 1000); }