Files
forwarder/worker/bizdocs_client.py
T
XikaandPaperclip d8daca15bd feat(backend): add FastAPI, worker, web nginx — full platform (BIT-26121)
- api/: FastAPI app with MySQL (accounts, forwarding_rules, messages)
  - GET/POST/PUT/DELETE /accounts + /accounts/{id}/test
  - GET /messages + /messages/{id}/retry
  - GET /stats
  - POST /connection/test
  - Auto-runs migrations/init.sql on startup
- worker/: Python IMAP poller + BizDocs upload (schedule every 5 min)
- web/: multi-stage Dockerfile — builds admin-ui via Node, serves via nginx
  - nginx proxies /api/ → api:8000, SPA fallback for React Router
- docker-compose.yml: updated web build context + mysql init.sql mount

Co-Authored-By: Paperclip <[email protected]>
2026-06-30 23:04:54 +00:00

33 lines
834 B
Python

"""BizDocs upload client."""
import logging
import httpx
log = logging.getLogger(__name__)
def upload_document(
bizdocs_url: str,
api_key: str,
filename: str,
data: bytes,
entity_id: str | None = None,
) -> str:
"""
Upload *data* as *filename* to the BizDocs API.
Returns the remote document ID string.
Raises on HTTP errors.
"""
url = bizdocs_url.rstrip("/") + "/documents"
headers = {"Authorization": f"Bearer {api_key}"}
files = {"file": (filename, data)}
params = {}
if entity_id:
params["entity_id"] = entity_id
with httpx.Client(timeout=60) as client:
resp = client.post(url, headers=headers, files=files, params=params)
resp.raise_for_status()
body = resp.json()
return str(body.get("id") or body.get("document_id") or resp.text)