Avinashnalla7 commited on
Commit
9f8c2b7
·
1 Parent(s): 623c2d7

Add PDF upload endpoint for worker

Browse files
Files changed (1) hide show
  1. backend/api.py +10 -1
backend/api.py CHANGED
@@ -6,7 +6,7 @@ from pathlib import Path
6
  from typing import Any, Dict
7
 
8
  from dotenv import load_dotenv
9
- from fastapi import FastAPI, HTTPException
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from fastapi.responses import FileResponse, PlainTextResponse
12
 
@@ -66,6 +66,15 @@ def get_pdf(pdf_id: str):
66
  resp.headers["X-PDF-Name"] = pdf_name
67
  return resp
68
 
 
 
 
 
 
 
 
 
 
69
 
70
  @app.post("/api/send-config")
71
  async def send_config(payload: Dict[str, Any]):
 
6
  from typing import Any, Dict
7
 
8
  from dotenv import load_dotenv
9
+ from fastapi import FastAPI, HTTPException, UploadFile, File, Form
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from fastapi.responses import FileResponse, PlainTextResponse
12
 
 
66
  resp.headers["X-PDF-Name"] = pdf_name
67
  return resp
68
 
69
+ @app.post("/api/pdf/{pdf_id}")
70
+ async def put_pdf(pdf_id: str, file: UploadFile = File(...), pdf_name: str = Form("")):
71
+ UPLOADS_DIR.mkdir(parents=True, exist_ok=True)
72
+ data = await file.read()
73
+ (UPLOADS_DIR / f"{pdf_id}.pdf").write_bytes(data)
74
+ if pdf_name:
75
+ (UPLOADS_DIR / f"{pdf_id}.name.txt").write_text(pdf_name.strip(), encoding="utf-8")
76
+ return {"ok": True}
77
+
78
 
79
  @app.post("/api/send-config")
80
  async def send_config(payload: Dict[str, Any]):