Update storage
Browse files
main.py
CHANGED
|
@@ -355,6 +355,56 @@ async def proxy_batch_stage(payload: dict = Body(...)):
|
|
| 355 |
return {"success": False, "message": f"Proxy Error (Internal): {str(e)}", "rows": []}
|
| 356 |
|
| 357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
@app.post("/proxy_flush_queue")
|
| 359 |
async def proxy_flush_queue(payload: dict = Body(...)):
|
| 360 |
username = str(payload.get("username", ""))
|
|
@@ -377,13 +427,18 @@ async def proxy_flush_queue(payload: dict = Body(...)):
|
|
| 377 |
|
| 378 |
|
| 379 |
@app.get("/proxy_preview/{session_id}/{row_id}/{preview_type}")
|
| 380 |
-
async def proxy_preview(session_id: str, row_id: str, preview_type: str, username: str = Query(""), size: str = Query("thumb")):
|
| 381 |
base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL
|
| 382 |
target_url = f"{base_url}/preview/{session_id}/{row_id}/{preview_type}"
|
| 383 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 384 |
|
| 385 |
def make_get():
|
| 386 |
-
return requests.get(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
response = await run_in_threadpool(make_get)
|
| 389 |
if response.status_code >= 400:
|
|
|
|
| 355 |
return {"success": False, "message": f"Proxy Error (Internal): {str(e)}", "rows": []}
|
| 356 |
|
| 357 |
|
| 358 |
+
@app.api_route("/proxy_process_jobs{rest:path}", methods=["GET", "POST"])
|
| 359 |
+
async def proxy_process_jobs(rest: str, request: Request):
|
| 360 |
+
"""Forward persistent processing-job uploads, polling, stop, and resume."""
|
| 361 |
+
username = request.query_params.get("username", "")
|
| 362 |
+
content_type = request.headers.get("content-type", "")
|
| 363 |
+
files = []
|
| 364 |
+
data = {}
|
| 365 |
+
json_body = None
|
| 366 |
+
if request.method == "POST":
|
| 367 |
+
if "multipart/form-data" in content_type:
|
| 368 |
+
form = await request.form()
|
| 369 |
+
for key, value in form.multi_items():
|
| 370 |
+
if hasattr(value, "filename"):
|
| 371 |
+
files.append((key, (value.filename, await value.read(), value.content_type)))
|
| 372 |
+
else:
|
| 373 |
+
data[key] = str(value)
|
| 374 |
+
username = username or data.get("username", "")
|
| 375 |
+
elif "application/json" in content_type:
|
| 376 |
+
json_body = await request.json()
|
| 377 |
+
if isinstance(json_body, dict):
|
| 378 |
+
username = username or str(json_body.get("username", ""))
|
| 379 |
+
base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL
|
| 380 |
+
target_url = f"{base_url}/process_jobs{rest}"
|
| 381 |
+
if request.url.query:
|
| 382 |
+
target_url += f"?{request.url.query}"
|
| 383 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 384 |
+
|
| 385 |
+
def make_request():
|
| 386 |
+
return request_with_hf_backoff(
|
| 387 |
+
getattr(requests, request.method.lower()),
|
| 388 |
+
target_url,
|
| 389 |
+
max_retries=0,
|
| 390 |
+
headers=headers,
|
| 391 |
+
files=files or None,
|
| 392 |
+
data=data or None,
|
| 393 |
+
json=json_body,
|
| 394 |
+
timeout=DATASET_PROXY_TIMEOUT_SECONDS,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
try:
|
| 398 |
+
response = await run_in_threadpool(make_request)
|
| 399 |
+
return Response(
|
| 400 |
+
content=response.content,
|
| 401 |
+
status_code=response.status_code,
|
| 402 |
+
media_type=response.headers.get("content-type", "application/json"),
|
| 403 |
+
)
|
| 404 |
+
except requests.exceptions.RequestException as exc:
|
| 405 |
+
return JSONResponse(status_code=502, content=proxy_error_payload("Proxy Error (Hugging Face)", exc))
|
| 406 |
+
|
| 407 |
+
|
| 408 |
@app.post("/proxy_flush_queue")
|
| 409 |
async def proxy_flush_queue(payload: dict = Body(...)):
|
| 410 |
username = str(payload.get("username", ""))
|
|
|
|
| 427 |
|
| 428 |
|
| 429 |
@app.get("/proxy_preview/{session_id}/{row_id}/{preview_type}")
|
| 430 |
+
async def proxy_preview(session_id: str, row_id: str, preview_type: str, username: str = Query(""), password: str = Query(""), size: str = Query("thumb")):
|
| 431 |
base_url = DEV_URL if username.strip().lower() == "devtest" else PROD_URL
|
| 432 |
target_url = f"{base_url}/preview/{session_id}/{row_id}/{preview_type}"
|
| 433 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 434 |
|
| 435 |
def make_get():
|
| 436 |
+
return requests.get(
|
| 437 |
+
target_url,
|
| 438 |
+
headers=headers,
|
| 439 |
+
params={"size": size, "username": username, "password": password},
|
| 440 |
+
timeout=30,
|
| 441 |
+
)
|
| 442 |
|
| 443 |
response = await run_in_threadpool(make_get)
|
| 444 |
if response.status_code >= 400:
|