feat(render-mode): Rich (LibreOffice) vs Standard (pandoc) toggle for office formats (.docx/.odt/.rtf); Rich default; 5 office tests; 152/152 green"
Test / Tests (Python 3.12) (push) Canceled after 0s
Test / Tests (Python 3.12) (push) Canceled after 0s
This commit is contained in:
@@ -88,7 +88,7 @@ _JOBS_LOCK = threading.Lock()
|
||||
TERMINAL_STATUSES = ("done", "error")
|
||||
|
||||
|
||||
def _register_job(epub_name: str) -> str:
|
||||
def _register_job(epub_name: str, render_mode: str = "rich") -> str:
|
||||
"""Register a job and enforce the 50-entry cap.
|
||||
|
||||
Eviction never touches in-flight (queued/working) jobs while any
|
||||
@@ -97,9 +97,13 @@ def _register_job(epub_name: str) -> str:
|
||||
app.py:69-73). Only when no terminal entry exists at all is the oldest
|
||||
job of any status evicted, preserving the plain 50-cap contract.
|
||||
"""
|
||||
render_mode = "rich" if render_mode in (None, "") else str(render_mode).lower()
|
||||
if render_mode not in ("rich", "standard"):
|
||||
render_mode = "rich"
|
||||
job = {
|
||||
"id": uuid.uuid4().hex[:12],
|
||||
"epub": epub_name,
|
||||
"render_mode": render_mode,
|
||||
"status": "queued",
|
||||
"progress": 0.0,
|
||||
"message": "queued",
|
||||
@@ -575,9 +579,12 @@ def _run_job(job_id: str, epub_path: Path) -> None:
|
||||
def _cb(pct, msg):
|
||||
_set_job(job_id, progress=pct, message=msg)
|
||||
|
||||
# AC: route office formats (.docx/.odt/.rtf) by the mode stored on the job.
|
||||
render_mode = JOBS.get(job_id, {}).get("render_mode", "rich")
|
||||
try:
|
||||
filename = converters.convert_file(
|
||||
epub_path, job_id, progress_cb=_cb,
|
||||
render_mode=render_mode,
|
||||
source_name=JOBS.get(job_id, {}).get("epub"))
|
||||
_set_job(job_id, status="done", progress=100.0, message="Done",
|
||||
filename=filename, error=None)
|
||||
@@ -652,7 +659,11 @@ def convert_upload():
|
||||
return jsonify(error=f"File too large (max {MAX_UPLOAD_MB} MB)"), 400
|
||||
if not WORKER_SLOTS.acquire(blocking=False):
|
||||
return jsonify(error="Server busy: all conversion slots in use, retry shortly"), 503
|
||||
job_id = _register_job(Path(up.filename).name)
|
||||
# AC: render_mode defaults to "rich"; stored on the job so the worker
|
||||
# routes office formats (.docx/.odt/.rtf) to the right converter. An
|
||||
# omitted render_mode field therefore behaves as rich.
|
||||
render_mode = request.form.get("render_mode", "rich")
|
||||
job_id = _register_job(Path(up.filename).name, render_mode=render_mode)
|
||||
dest = UPLOAD_DIR / f"{job_id}{Path(up.filename).suffix.lower()}"
|
||||
try:
|
||||
with open(dest, "wb") as out:
|
||||
|
||||
Reference in New Issue
Block a user