File Change
app/internal/storage.py Replaced make_public() + public_url with a v2 signed URL (1-year expiry, no public bucket needed) app/main.py Releases all in-use tokens at startup — tokens from previous sessions are cleared automatically app/routers/tokens.py Added POST /tokens/flush to force-release orphaned tokens on demand
This commit is contained in:
@@ -8,11 +8,30 @@ from app.internal.node_sweeper import sweeper_loop
|
||||
from app.config import settings
|
||||
from app.internal.auth import require_firebase_token, require_service_or_firebase_token
|
||||
from app.routers import nodes, systems, calls, upload, tokens, incidents, alerts
|
||||
from app.internal import firestore as fstore
|
||||
|
||||
|
||||
async def _release_orphaned_tokens():
|
||||
"""Release all in-use tokens on startup — voice connections don't survive server restarts."""
|
||||
def _find():
|
||||
from app.internal.firestore import db
|
||||
return [d for d in db.collection("bot_tokens").where("in_use", "==", True).stream()]
|
||||
|
||||
results = await asyncio.to_thread(_find)
|
||||
for doc in results:
|
||||
await fstore.doc_update("bot_tokens", doc.id, {
|
||||
"in_use": False,
|
||||
"assigned_node_id": None,
|
||||
"assigned_at": None,
|
||||
})
|
||||
if results:
|
||||
logger.info(f"Released {len(results)} orphaned token(s) on startup.")
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
logger.info("DRB C2 Core starting.")
|
||||
await _release_orphaned_tokens()
|
||||
|
||||
await mqtt_handler.connect()
|
||||
sweeper_task = asyncio.create_task(sweeper_loop())
|
||||
|
||||
Reference in New Issue
Block a user