new version of rmlworkorder

This commit is contained in:
Luca Haid
2025-07-23 20:44:25 +02:00
parent f7218ab144
commit 8621cba7ff
18 changed files with 1379 additions and 726 deletions

View File

@@ -92,27 +92,24 @@ class FileController extends mfBaseController {
$id = $this->request->id;
$size = $this->request->size;
if (!is_numeric($id) || $id < 1) {
http_response_code(400);
self::returnJson(["error" => "Invalid File ID"]);
return;
}
if (!is_numeric($id) || $id < 1) self::sendError("Invalid File ID");
$file = new File($id);
if (!$file->id) {
http_response_code(404);
self::returnJson(["error" => "File record not found"]);
return;
}
if (!$file->id) self::sendError("File record not found");
$originalPath = MFUPLOAD_FILE_SAVE_PATH . ($file->subfolder ? "/{$file->subfolder}" : "") . "/{$file->store_filename}";
if (!is_readable($originalPath)) {
http_response_code(404);
self::returnJson(["error" => "Physical file not found"]);
return;
}
if (!is_readable($originalPath)) self::sendError("Physical file not found");
$imageInfo = @getimagesize($originalPath);
if ($imageInfo === false && mime_content_type($originalPath) === 'application/pdf') {
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . ($file->orig_filename ?: $file->store_filename) . '"');
readfile($originalPath);
exit;
}
if ($imageInfo === false) {
$this->downloadAction();
return;
@@ -129,18 +126,13 @@ class FileController extends mfBaseController {
$cacheDir = TEMP_DIR . "/thumbnails";
@mkdir($cacheDir, 0775, true);
$cachedPath = "{$cacheDir}/{$id}_{$size}." . pathinfo($originalPath, PATHINFO_EXTENSION);
if (!file_exists($cachedPath)) {
$command = "convert " . escapeshellarg($originalPath) . " -resize " . escapeshellarg($sizeDimensions[$size]) . " " . escapeshellarg($cachedPath);
exec($command, $output, $return_var);
if ($return_var !== 0) {
http_response_code(500);
self::returnJson(["error" => "Failed to create thumbnail."]);
return;
}
if ($return_var !== 0) self::sendError("Failed to create thumbnail.");
}
header('Content-Type: ' . $imageInfo['mime']);
@@ -148,5 +140,4 @@ class FileController extends mfBaseController {
readfile($cachedPath);
exit;
}
}