Spaces:
Build error
Build error
| """ | |
| project @ NTO-TCP-HF | |
| created @ 2024-10-28 | |
| author @ github.com/ishworrsubedii | |
| """ | |
| import time | |
| from datetime import datetime, timedelta, timezone | |
| from fastapi import FastAPI, Depends, HTTPException | |
| from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials | |
| from starlette.middleware.cors import CORSMiddleware | |
| from starlette.responses import JSONResponse | |
| from src.api.image_prep_api import preprocessing_router | |
| from src.api.nto_api import nto_cto_router | |
| from src.api.image_regeneration_api import image_regeneration_router | |
| from src.api.batch_api import batch_router | |
| from src.api.mannequin_to_model_api import mto_router | |
| from src.api.nto_api import supabase | |
| security = HTTPBearer() | |
| async def verify_login_token(credentials: HTTPAuthorizationCredentials = Depends(security)): | |
| try: | |
| response = supabase.table("JewelMirrorUserLogins").select("*").eq("LoginToken", | |
| credentials.credentials).execute() | |
| if not response.data: | |
| raise HTTPException(status_code=401, detail="Unauthorized: Token not found") | |
| token_data = response.data[0] | |
| created_at = datetime.fromisoformat(token_data["UpdatedAt"].replace("Z", "+00:00")) | |
| current_time = datetime.now(timezone.utc) | |
| time_difference = current_time - created_at | |
| if time_difference <= timedelta(minutes=30): | |
| return JSONResponse({"status": "Authorized", "message": "Token is valid"}, status_code=200) | |
| raise HTTPException(status_code=401, detail="Unauthorized: Token expired") | |
| except Exception as e: | |
| print(f"Token verification error: {e}") | |
| raise HTTPException(status_code=401, detail="Invalid token") | |
| app = FastAPI() | |
| app.include_router(nto_cto_router, tags=["NTO-CTO"]) | |
| app.include_router(preprocessing_router, tags=["Image-Preprocessing"]) | |
| app.include_router(image_regeneration_router, tags=["Image-Regeneration"]) | |
| time.sleep(1) | |
| app.include_router(batch_router, tags=['Realtime']) | |
| app.include_router(mto_router, tags=["MTO"]) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) |