|
from fastapi import FastAPI, Request |
|
from fastapi.responses import JSONResponse |
|
from fastapi.middleware.gzip import GZipMiddleware |
|
from App import bot |
|
from telethon import TelegramClient |
|
from telethon.sessions import StringSession |
|
from .Users.UserRoutes import user_router |
|
from .modelInit import models, database |
|
from .Transcription.TranscriptionRoutes import transcription_router |
|
from .Streaming.StreamingRoutes import streaming_router |
|
from .UserTranscriptions.UserTranscriptionsRoutes import user_transcriptions_router |
|
from .Monitor.monitorRoutes import monitor_router |
|
|
|
from .Embedding.EmbeddingRoutes import embeddigs_router |
|
from .Chat.ChatRoutes import chat_router |
|
|
|
from fastapi.middleware.cors import CORSMiddleware |
|
from fastapi_jwt_auth.exceptions import AuthJWTException |
|
|
|
import logging, orm |
|
|
|
|
|
|
|
logging.basicConfig( |
|
level=logging.DEBUG, |
|
format="%(asctime)s - %(levelname)s - %(message)s", |
|
datefmt="%Y-%m-%d %H:%M:%S", |
|
) |
|
|
|
|
|
app = FastAPI() |
|
origins = ["*"] |
|
|
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_origins=origins, |
|
allow_credentials=True, |
|
allow_methods=["*"], |
|
allow_headers=["*"], |
|
) |
|
app.add_middleware(GZipMiddleware, minimum_size=1000) |
|
|
|
|
|
@app.exception_handler(AuthJWTException) |
|
def authjwt_exception_handler(request: Request, exc: AuthJWTException): |
|
return JSONResponse(status_code=exc.status_code, content={"detail": exc.message}) |
|
|
|
|
|
@app.on_event("startup") |
|
async def startup_event(): |
|
await bot.start() |
|
|
|
|
|
|
|
|
|
if not database.is_connected: |
|
await database.connect() |
|
print("connected!") |
|
|
|
|
|
@app.on_event("shutdown") |
|
async def shutdown_event(): |
|
|
|
|
|
|
|
|
|
if not database.is_connected: |
|
await database.disconnect() |
|
print("shutting down!") |
|
|
|
|
|
@app.get("/") |
|
async def landing_page(): |
|
return {"code": 200, "message": "we are back!"} |
|
|
|
|
|
app.include_router(user_router) |
|
app.include_router(transcription_router) |
|
app.include_router(streaming_router) |
|
app.include_router(monitor_router) |
|
app.include_router(user_transcriptions_router) |
|
app.include_router(embeddigs_router) |
|
app.include_router(chat_router) |
|
|