Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
-
from fastapi import FastAPI, Request, HTTPException, status
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from fastapi.responses import Response, JSONResponse, StreamingResponse, RedirectResponse
|
| 6 |
import httpx
|
|
@@ -13,6 +13,8 @@ from urllib.parse import quote
|
|
| 13 |
import uuid
|
| 14 |
import base64
|
| 15 |
from subscriptions import fetch_subscription
|
|
|
|
|
|
|
| 16 |
WAN_SPACE = "https://huggingface.co/spaces/Wan-AI/Wan2.1"
|
| 17 |
WAN_API_BASE = f"{WAN_SPACE}/gradio_api"
|
| 18 |
|
|
@@ -919,16 +921,15 @@ async def genvideo_airforce(request: Request, prompt: str = None):
|
|
| 919 |
},
|
| 920 |
)
|
| 921 |
|
| 922 |
-
@app.get("/subscription
|
| 923 |
-
async def
|
| 924 |
-
|
| 925 |
-
|
|
|
|
|
|
|
| 926 |
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
if not email:
|
| 931 |
-
raise HTTPException(400, "email is required")
|
| 932 |
|
| 933 |
-
|
| 934 |
-
return result or {"email": email, "subscription": None}
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
+
from fastapi import FastAPI, Request, HTTPException, status, Header
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from fastapi.responses import Response, JSONResponse, StreamingResponse, RedirectResponse
|
| 6 |
import httpx
|
|
|
|
| 13 |
import uuid
|
| 14 |
import base64
|
| 15 |
from subscriptions import fetch_subscription
|
| 16 |
+
from typing import Optional
|
| 17 |
+
|
| 18 |
WAN_SPACE = "https://huggingface.co/spaces/Wan-AI/Wan2.1"
|
| 19 |
WAN_API_BASE = f"{WAN_SPACE}/gradio_api"
|
| 20 |
|
|
|
|
| 921 |
},
|
| 922 |
)
|
| 923 |
|
| 924 |
+
@app.get("/subscription")
|
| 925 |
+
async def get_subscription(authorization: Optional[str] = Header(None)):
|
| 926 |
+
if not authorization or not authorization.startswith("Bearer "):
|
| 927 |
+
raise HTTPException(401, "Missing or invalid Authorization header")
|
| 928 |
+
|
| 929 |
+
jwt = authorization.split(" ", 1)[1]
|
| 930 |
|
| 931 |
+
result = await fetch_subscription(jwt)
|
| 932 |
+
if "error" in result:
|
| 933 |
+
raise HTTPException(401, result["error"])
|
|
|
|
|
|
|
| 934 |
|
| 935 |
+
return result
|
|
|