Add image upload support, file handling improvements, and OpenAI integration

- Introduced `uploadRoute` to handle image uploads with MIME type validation and size restrictions.
- Added `upload_store` class for managing file storage and generating presigned URLs for upload/download.
- Enhanced file server to differentiate between PDFs and uploaded files, supporting dynamic content delivery.
- Integrated OpenAI module for License Plate Recognition (LPR), including API configuration and schema validation.
- Updated core structure with new interfaces (`minio_uploads_i`, `openai_i`) and classes (`openai`, `upload_store`).
- Adjusted `index.php` and file routes to support dynamic MIME checks and direct link generation.
This commit is contained in:
Jeppe Bundgaard
2025-08-18 16:50:30 +02:00
parent 841062bfca
commit a0fd41fba1
14 changed files with 777 additions and 26 deletions
+27 -4
View File
@@ -5,6 +5,7 @@ namespace traits;
use classes\authentication;
use classes\recaptcha;
use classes\response;
use Exception;
use objects\logs_o;
trait route_t
@@ -54,6 +55,28 @@ trait route_t
return true;
}
/**
* Require a value to be in the given array
* @param mixed $value The value to check
* @param array $array The array to check against
* @return bool
* @throws Exception If the value is not in the array
*/
public function requireInArray(mixed $value, array $array): bool
{
global $response;
// Check if the value is in the array
if (!in_array($value, $array)) {
$response->error(json_encode([
'message' => 'Unexpected value',
'expected' => $array,
'got' => $value,
'type' => gettype($value)
]), 400);
}
return true;
}
public function requireSameLength(mixed $arg1, mixed $arg2): bool
{
global $response;
@@ -214,7 +237,7 @@ trait route_t
(new logs_o())->add('global', 'global', 1, $user->id, 'PERMISSION_DENIED', 'Permission denied. Missing permission: ' . $permission);
$response->error('Permission denied. Missing permission: ' . $permission . ' for user: ' . $user->id . ' In group: ' . $user->group_id->value(), 403);
}
} catch (\Exception $e) {
} catch (Exception $e) {
$response->error($e->getMessage(), 400);
}
return true;
@@ -237,7 +260,7 @@ trait route_t
$response->error('Authentication failed. Invalid or missing token.', 401);
}
return $user->hasPermission($permission);
} catch (\Exception $e) {
} catch (Exception $e) {
$response->error($e->getMessage(), 400);
}
}
@@ -416,7 +439,7 @@ trait route_t
(new logs_o())->add('global', 'global', 1, 0, 'AUTHENTICATION_FAILED', 'Authentication failed. Invalid, or missing API key');
$response->error('Authentication failed. Invalid or missing API key.', 401);
}
} catch (\Exception $e) {
} catch (Exception $e) {
$response->error($e->getMessage(), 400);
}
return true;
@@ -450,7 +473,7 @@ trait route_t
(new logs_o())->add('global', 'global', 1, 0, 'AUTHENTICATION_FAILED', 'Authentication failed. Invalid, or missing reCAPTCHA');
$response->error('Authentication failed. Invalid or missing reCAPTCHA.', 401);
}
} catch (\Exception $e) {
} catch (Exception $e) {
$response->error($e->getMessage(), 400);
}
return true;