Spaces:
Sleeping
Sleeping
Commit ·
e3b7e75
1
Parent(s): 9ea86b6
Make /api/send-config store config even if PDF missing
Browse files- backend/api.py +7 -6
backend/api.py
CHANGED
|
@@ -61,9 +61,7 @@ def _get_env_required(key: str) -> str:
|
|
| 61 |
|
| 62 |
@app.get("/health")
|
| 63 |
def health():
|
| 64 |
-
return {"ok": True}
|
| 65 |
-
|
| 66 |
-
|
| 67 |
@app.get("/api/pdf/{pdf_id}")
|
| 68 |
def get_pdf(pdf_id: str):
|
| 69 |
path = UPLOADS_DIR / f"{pdf_id}.pdf"
|
|
@@ -109,10 +107,13 @@ async def send_config(request: Request):
|
|
| 109 |
raise HTTPException(status_code=400, detail="Missing config object")
|
| 110 |
|
| 111 |
# PDF must exist in API uploads (worker uploads it first)
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
| 115 |
|
|
|
|
|
|
|
| 116 |
name_path = UPLOADS_DIR / f"{pdf_id}.name.txt"
|
| 117 |
pdf_name = name_path.read_text(encoding="utf-8").strip() if name_path.exists() else f"{pdf_id}.pdf"
|
| 118 |
|
|
|
|
| 61 |
|
| 62 |
@app.get("/health")
|
| 63 |
def health():
|
| 64 |
+
return {"ok": True, "stored": str(out_path), "pdf_attached": bool(pdf_exists)}
|
|
|
|
|
|
|
| 65 |
@app.get("/api/pdf/{pdf_id}")
|
| 66 |
def get_pdf(pdf_id: str):
|
| 67 |
path = UPLOADS_DIR / f"{pdf_id}.pdf"
|
|
|
|
| 107 |
raise HTTPException(status_code=400, detail="Missing config object")
|
| 108 |
|
| 109 |
# PDF must exist in API uploads (worker uploads it first)
|
| 110 |
+
# Always store config, even if PDF is missing in this container
|
| 111 |
+
CONFIGS_DIR.mkdir(parents=True, exist_ok=True)
|
| 112 |
+
out_path = CONFIGS_DIR / f"{pdf_id}__{template_id}.json"
|
| 113 |
+
out_path.write_text(json.dumps({"pdf_id": pdf_id, "template_id": template_id, "config": config}, indent=2), encoding="utf-8")
|
| 114 |
|
| 115 |
+
pdf_path = UPLOADS_DIR / f"{pdf_id}.pdf"
|
| 116 |
+
pdf_exists = pdf_path.exists()
|
| 117 |
name_path = UPLOADS_DIR / f"{pdf_id}.name.txt"
|
| 118 |
pdf_name = name_path.read_text(encoding="utf-8").strip() if name_path.exists() else f"{pdf_id}.pdf"
|
| 119 |
|