Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -13,7 +13,7 @@ import os
|
|
| 13 |
import time
|
| 14 |
import asyncio
|
| 15 |
from typing import List, Optional, Dict
|
| 16 |
-
from fastapi import FastAPI, UploadFile, File, HTTPException, Depends, BackgroundTasks, Header
|
| 17 |
from fastapi.middleware.cors import CORSMiddleware
|
| 18 |
from pydantic import BaseModel
|
| 19 |
from threading import Lock
|
|
@@ -190,6 +190,7 @@ async def health_check():
|
|
| 190 |
|
| 191 |
@app.post("/upload", response_model=UploadResponse)
|
| 192 |
async def upload_pdf(
|
|
|
|
| 193 |
file: UploadFile = File(...),
|
| 194 |
user_id: str = Depends(get_current_user),
|
| 195 |
x_api_key: Optional[str] = Header(None, alias="X-API-KEY"),
|
|
@@ -214,6 +215,14 @@ async def upload_pdf(
|
|
| 214 |
raise HTTPException(413, "File too large (max 10MB)")
|
| 215 |
|
| 216 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
# Save to a temp file so background worker can access it
|
| 218 |
base_dir = os.path.dirname(os.path.abspath(__file__))
|
| 219 |
tmp_dir = os.path.join(base_dir, 'tmp_uploads')
|
|
@@ -381,4 +390,4 @@ async def get_stats(user_id: str = Depends(get_current_user)):
|
|
| 381 |
if __name__ == "__main__":
|
| 382 |
import uvicorn
|
| 383 |
port = int(os.environ.get("PORT", 8000))
|
| 384 |
-
uvicorn.run("main:app", host="0.0.0.0", port=port, reload=True)
|
|
|
|
| 13 |
import time
|
| 14 |
import asyncio
|
| 15 |
from typing import List, Optional, Dict
|
| 16 |
+
from fastapi import FastAPI, UploadFile, File, HTTPException, Depends, BackgroundTasks, Header, Request
|
| 17 |
from fastapi.middleware.cors import CORSMiddleware
|
| 18 |
from pydantic import BaseModel
|
| 19 |
from threading import Lock
|
|
|
|
| 190 |
|
| 191 |
@app.post("/upload", response_model=UploadResponse)
|
| 192 |
async def upload_pdf(
|
| 193 |
+
request: Request,
|
| 194 |
file: UploadFile = File(...),
|
| 195 |
user_id: str = Depends(get_current_user),
|
| 196 |
x_api_key: Optional[str] = Header(None, alias="X-API-KEY"),
|
|
|
|
| 215 |
raise HTTPException(413, "File too large (max 10MB)")
|
| 216 |
|
| 217 |
try:
|
| 218 |
+
# Debug: log a subset of incoming headers to help diagnose authentication issues
|
| 219 |
+
try:
|
| 220 |
+
hdrs = dict(request.headers)
|
| 221 |
+
# Only print a few header keys to avoid leaking secrets in logs
|
| 222 |
+
interesting = {k: hdrs.get(k) for k in ["x-api-key", "authorization", "host", "user-agent"] if hdrs.get(k)}
|
| 223 |
+
print(f"🔍 Incoming upload headers (filtered): {interesting}")
|
| 224 |
+
except Exception:
|
| 225 |
+
pass
|
| 226 |
# Save to a temp file so background worker can access it
|
| 227 |
base_dir = os.path.dirname(os.path.abspath(__file__))
|
| 228 |
tmp_dir = os.path.join(base_dir, 'tmp_uploads')
|
|
|
|
| 390 |
if __name__ == "__main__":
|
| 391 |
import uvicorn
|
| 392 |
port = int(os.environ.get("PORT", 8000))
|
| 393 |
+
uvicorn.run("main:app", host="0.0.0.0", port=port, reload=True)
|