Skip to content
Snippets Groups Projects

Interface admin

Merged Antoine Gaudron-Desjardins requested to merge interface_admin into main
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
+ 23
3
from fastapi import FastAPI
from fastapi import Cookie, Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
from sqlalchemy.orm import Session
from dotenv import load_dotenv
from threading import Thread
from asyncio import run
import os
from db import database, models
from db import database, models, crud
from db.database import get_db
from routers import *
from video_capture import handle_cameras
app = FastAPI(docs_url="/api/docs", openapi_url="/api/openapi.json")
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
# load environment variables
load_dotenv()
@@ -35,6 +40,21 @@ async def on_startup():
t.start()
# Docs OpenAPI
@app.get("/api/openapi.json")
async def get_open_api_endpoint(connect_id: str = Cookie(...), db: Session = Depends(get_db)):
user = crud.get_user(connect_id, db)
if user.admin:
return JSONResponse(get_openapi(title="FastAPI", version=1, routes=app.routes))
@app.get("/api/docs")
async def get_documentation(connect_id: str = Cookie(...), db: Session = Depends(get_db)):
user = crud.get_user(connect_id, db)
if user.admin:
return get_swagger_ui_html(openapi_url="/api/openapi.json", title="docs")
# Integration of routers
app.include_router(infos.router)
app.include_router(records.router)
Loading