This commit is contained in:
2026-06-16 09:23:40 +02:00
parent 20571c9e4b
commit 8bb23ee563
15 changed files with 3101 additions and 611 deletions
+50 -8
View File
@@ -16,6 +16,30 @@ def health():
})
def get_float_or_none(name):
value = request.form.get(name, "").strip()
if value == "":
return None
try:
return float(value)
except ValueError:
return None
def get_int_or_default(name, default=1):
value = request.form.get(name, "").strip()
if value == "":
return default
try:
return int(value)
except ValueError:
return default
@app.route("/calculate", methods=["POST"])
def calculate():
try:
@@ -41,19 +65,37 @@ def calculate():
pdf_bytes = uploaded_file.read()
scale_ratio = request.form.get("scale_ratio", "1")
scale_ratio = get_float_or_none("scale_ratio")
try:
scale_ratio = float(scale_ratio)
if scale_ratio <= 0:
scale_ratio = 1.0
except ValueError:
scale_ratio = 1.0
if scale_ratio is not None and scale_ratio <= 0:
scale_ratio = None
roi = {
"x": get_float_or_none("roi_x"),
"y": get_float_or_none("roi_y"),
"width": get_float_or_none("roi_width"),
"height": get_float_or_none("roi_height"),
"page": get_int_or_default("roi_page", 1)
}
has_roi = (
roi["x"] is not None and
roi["y"] is not None and
roi["width"] is not None and
roi["height"] is not None and
roi["width"] > 0 and
roi["height"] > 0
)
mode = request.form.get("mode", "auto_roi")
result = calculate_pdf_vector_area(
pdf_bytes=pdf_bytes,
filename=uploaded_file.filename,
scale_ratio=scale_ratio
scale_ratio=scale_ratio,
profile_color=None,
roi=roi if has_roi else None,
mode=mode
)
status_code = 200 if result.get("success") else 422