Spaces:
Runtime error
Runtime error
feat: enforce strict Bearer Token auth for HF Space interactions
Browse files
app.py
CHANGED
|
@@ -167,8 +167,12 @@ async def vault_media(request: VaultRequest, background_tasks: BackgroundTasks,
|
|
| 167 |
return {"status": "accepted", "message": "Vaulting started"}
|
| 168 |
|
| 169 |
@app.get("/proxy-stream/{file_id}")
|
| 170 |
-
async def proxy_stream(file_id: str, type: str = "audio",
|
| 171 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
raise HTTPException(status_code=401, detail="Unauthorized")
|
| 173 |
|
| 174 |
async def stream_generator():
|
|
|
|
| 167 |
return {"status": "accepted", "message": "Vaulting started"}
|
| 168 |
|
| 169 |
@app.get("/proxy-stream/{file_id}")
|
| 170 |
+
async def proxy_stream(file_id: str, type: str = "audio", authorization: str = Header(None)):
|
| 171 |
+
if not authorization or not authorization.startswith("Bearer "):
|
| 172 |
+
raise HTTPException(status_code=401, detail="Unauthorized")
|
| 173 |
+
|
| 174 |
+
token = authorization.split(" ")[1]
|
| 175 |
+
if token != SECRET_TOKEN:
|
| 176 |
raise HTTPException(status_code=401, detail="Unauthorized")
|
| 177 |
|
| 178 |
async def stream_generator():
|