modified: app.py
modified: templates/itemeditor_command_storage.html
This commit is contained in:
10
app.py
10
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
|
||||
|
||||
@@ -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 = '<span style="color: #ff5555;">Expired</span>';
|
||||
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 = '<span style="color: #ff5555;">Expired</span>';
|
||||
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);
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user