Transition to Docker-based framework

This commit is contained in:
Jo Eskil
2025-11-13 17:27:18 +01:00
parent 2ce96386e3
commit 5475698fc5
14 changed files with 185 additions and 40 deletions

35
main.py
View File

@@ -8,10 +8,16 @@ from sqlalchemy.orm import Session
from chat_listeners import listen_youtube_chat, listen_twitch_chat
from auth import router as auth_router, serializer
from database import get_db, User
from database import get_db, User, create_tables
app = FastAPI()
@app.on_event("startup")
async def startup_event():
create_tables()
# The chat listeners will be started dynamically based on user activity
# and not on application startup.
class SessionMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next):
response = await call_next(request)
@@ -28,33 +34,6 @@ class SessionMiddleware(BaseHTTPMiddleware):
request.state.user = None
return response
app.add_middleware(SessionMiddleware)
def get_current_user(request: Request):
return request.state.user
app.include_router(auth_router, prefix="/auth") # Include the auth router
connected_clients = []
async def broadcast_message(message: dict):
# Convert the message dictionary to a JSON string before sending
message_json = json.dumps(message)
for client in connected_clients:
try:
await client.send_text(message_json)
except RuntimeError:
# Handle cases where client might have disconnected
connected_clients.remove(client)
@app.on_event("startup")
async def startup_event():
# Start chat listeners in the background
# Replace with actual video ID and Twitch token/channel
# For now, using placeholders. These will need to be configured.
asyncio.create_task(listen_youtube_chat("YOUR_YOUTUBE_VIDEO_ID", broadcast_message))
asyncio.create_task(listen_twitch_chat("YOUR_TWITCH_OAUTH_TOKEN", "YOUR_TWITCH_CHANNEL", broadcast_message))
@app.get("/")
async def read_root():
return {"Hello": "World"}