Commit
·
8a3a45c
1
Parent(s):
63bf853
Slight Edit
Browse files
{Unused Codes → FileStream/server/API}/listings.py
RENAMED
|
File without changes
|
FileStream/server/__init__.py
CHANGED
|
@@ -9,6 +9,29 @@ from .Authentication import auth
|
|
| 9 |
from .routes_main import routes
|
| 10 |
from FileStream.bot import MULTI_CLIENTS, WORK_LOADS, ACTIVE_CLIENTS
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
async def root_route_handler(request):
|
| 13 |
return web.json_response({"status": "alive", "message": "Server is running","active_clients":[{"client_name": tg_connect.client.name} for client_id, tg_connect in ACTIVE_CLIENTS.items()],"public_ip":request.remote})
|
| 14 |
|
|
|
|
| 9 |
from .routes_main import routes
|
| 10 |
from FileStream.bot import MULTI_CLIENTS, WORK_LOADS, ACTIVE_CLIENTS
|
| 11 |
|
| 12 |
+
"""
|
| 13 |
+
from .Middlewares.jwt_middleware import jwt_middleware
|
| 14 |
+
from .Middlewares.app_token_middleware import app_token_middleware
|
| 15 |
+
from .Middlewares.logging_middleware import logging_middleware
|
| 16 |
+
#from .Middlewares.rate_limit_middleware import rate_limit_middleware
|
| 17 |
+
"""
|
| 18 |
+
# Set time to consider a client inactive (e.g., 10 minutes)
|
| 19 |
+
INACTIVITY_TIMEOUT = 180 # 3 minutes
|
| 20 |
+
|
| 21 |
+
async def clear_inactive_clients():
|
| 22 |
+
"""Clear inactive clients from ACTIVE_CLIENTS."""
|
| 23 |
+
await asyncio.sleep(INACTIVITY_TIMEOUT) # Check every INACTIVITY_TIMEOUT seconds
|
| 24 |
+
now = asyncio.get_event_loop().time() # Get current time
|
| 25 |
+
inactive_clients = [
|
| 26 |
+
client_id for client_id, tg_connect in ACTIVE_CLIENTS.items()
|
| 27 |
+
if now - tg_connect.last_activity > INACTIVITY_TIMEOUT # Compare with last_activity timestamp
|
| 28 |
+
]
|
| 29 |
+
for client in inactive_clients:
|
| 30 |
+
# Log and clear the inactive client
|
| 31 |
+
logging.info(f"** Clearing inactive client: {client.name}")
|
| 32 |
+
del ACTIVE_CLIENTS[client] # Remove inactive client from ACTIVE_CLIENTS
|
| 33 |
+
|
| 34 |
+
|
| 35 |
async def root_route_handler(request):
|
| 36 |
return web.json_response({"status": "alive", "message": "Server is running","active_clients":[{"client_name": tg_connect.client.name} for client_id, tg_connect in ACTIVE_CLIENTS.items()],"public_ip":request.remote})
|
| 37 |
|