- Add VkConnection model with is_online/last_checked_at fields - Add /vk OAuth flow (connect/callback/disconnect/page) - Add VK entry to connections dashboard - Extend background health checker to check VK tokens via users.get - Add Alembic migration for vk_connections table - Add VK_CLIENT_ID/SECRET/SCOPES/API_VERSION config settings Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import asyncio
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI, Depends, Request
|
|
from fastapi.responses import RedirectResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
from starlette.middleware.sessions import SessionMiddleware
|
|
|
|
from web.auth import get_current_user
|
|
from web.config import settings
|
|
from web.health_checker import health_check_loop
|
|
from web.models import User
|
|
from web.routes import auth, profile, reset, evotor, vk
|
|
from web.routes import connections
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
task = asyncio.create_task(health_check_loop(settings.HEALTH_CHECK_INTERVAL_SECONDS))
|
|
yield
|
|
task.cancel()
|
|
try:
|
|
await task
|
|
except asyncio.CancelledError:
|
|
pass
|
|
|
|
|
|
app = FastAPI(title="EvoSync — Личный кабинет", lifespan=lifespan)
|
|
|
|
app.add_middleware(SessionMiddleware, secret_key=settings.SECRET_KEY)
|
|
app.mount("/static", StaticFiles(directory="web/static"), name="static")
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(profile.router)
|
|
app.include_router(reset.router)
|
|
app.include_router(evotor.router)
|
|
app.include_router(connections.router)
|
|
app.include_router(vk.router)
|
|
|
|
|
|
@app.get("/")
|
|
def home(request: Request, user: User | None = Depends(get_current_user)):
|
|
if user:
|
|
return RedirectResponse("/profile", 302)
|
|
return RedirectResponse("/login", 302)
|