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
+124
View File
@@ -0,0 +1,124 @@
<?php
header('Content-Type: application/json; charset=utf-8');
require_once(__DIR__ . '/include/headscript.php');
try {
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$iduser = $iduserlogin ?? null;
$rawInput = file_get_contents('php://input');
$input = json_decode($rawInput, true);
if (!is_array($input)) {
throw new Exception('Payload JSON non valido.');
}
$id = (int)($input['id'] ?? 0);
if ($id <= 0) {
throw new Exception('ID non valido.');
}
$roiX = isset($input['roi_x']) ? (float)$input['roi_x'] : null;
$roiY = isset($input['roi_y']) ? (float)$input['roi_y'] : null;
$roiW = isset($input['roi_width']) ? (float)$input['roi_width'] : null;
$roiH = isset($input['roi_height']) ? (float)$input['roi_height'] : null;
$roiPage = isset($input['roi_page']) ? (int)$input['roi_page'] : 1;
$mode = $input['calculation_mode'] ?? 'auto_roi';
if ($roiX === null || $roiY === null || $roiW === null || $roiH === null) {
throw new Exception('ROI non valida.');
}
if ($roiW <= 0 || $roiH <= 0) {
throw new Exception('Dimensioni ROI non valide.');
}
if ($roiX < 0 || $roiY < 0 || $roiX > 1 || $roiY > 1 || $roiW > 1 || $roiH > 1) {
throw new Exception('Coordinate ROI fuori scala.');
}
$allowedModes = [
'auto_roi',
'stitch_contour',
'filled_union',
'closed_path'
];
if (!in_array($mode, $allowedModes, true)) {
$mode = 'auto_roi';
}
if ($iduser === null || $iduser === '') {
$stmt = $pdo->prepare("
UPDATE cad_area_jobs
SET
roi_x = ?,
roi_y = ?,
roi_width = ?,
roi_height = ?,
roi_page = ?,
calculation_mode = ?,
status = 'uploaded',
message = NULL
WHERE id = ?
");
$stmt->execute([
$roiX,
$roiY,
$roiW,
$roiH,
$roiPage,
$mode,
$id
]);
} else {
$stmt = $pdo->prepare("
UPDATE cad_area_jobs
SET
roi_x = ?,
roi_y = ?,
roi_width = ?,
roi_height = ?,
roi_page = ?,
calculation_mode = ?,
status = 'uploaded',
message = NULL
WHERE id = ?
AND iduser = ?
");
$stmt->execute([
$roiX,
$roiY,
$roiW,
$roiH,
$roiPage,
$mode,
$id,
$iduser
]);
}
if ($stmt->rowCount() === 0) {
throw new Exception('Nessun record aggiornato. Controlla ID o utente.');
}
echo json_encode([
'success' => true,
'message' => 'ROI salvata correttamente.'
]);
exit;
} catch (Throwable $e) {
error_log('CAD area save ROI error: ' . $e->getMessage());
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
exit;
}
File diff suppressed because it is too large Load Diff