File size: 2,214 Bytes
1fb00de
 
 
 
 
71fcf3b
f33f113
6104dd3
f33f113
 
1fb00de
dfee28c
5a186b4
1fb00de
 
8789af7
71fcf3b
b8f6290
f33f113
1fb00de
f33f113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfee28c
f33f113
 
 
 
 
 
 
 
1b92f63
1fb00de
 
8789af7
b8f6290
71fcf3b
6104dd3
b8f6290
 
6104dd3
 
 
 
 
 
1b92f63
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
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=["*"],
)