modified: app.py

modified:   templates/itemeditor_command_storage.html
This commit is contained in:
SimolZimol
2026-01-07 04:15:55 +01:00
parent e90d28cc10
commit 26a7169515
2 changed files with 19 additions and 14 deletions

10
app.py
View File

@@ -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