- 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.
86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
use interfaces\minio_uploads_i;
|
|
use traits\minio_t;
|
|
|
|
class upload_store implements minio_uploads_i
|
|
{
|
|
use minio_t;
|
|
|
|
public function __construct()
|
|
{
|
|
self::setBucket('uploads'); // Change the bucket to 'pdfs'
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function generatePresignedUrl(string $objectName, int $expiry = 3600): string
|
|
{
|
|
// Generate a presigned URL for the given object name with the specified expiry time
|
|
return self::getPresignedUrl($objectName, $expiry, true);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function isValidFileName(string $fileName): bool
|
|
{
|
|
// Check if the file name is valid
|
|
return preg_match('/^[a-zA-Z0-9_\-.]+$/', $fileName) === 1;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function isValidFilePath(string $filePath): bool
|
|
{
|
|
// Check if the file path is valid
|
|
return preg_match('/^[a-zA-Z0-9_\-\/.]+$/', $filePath) === 1;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function requireValidFileName(string $fileName): void
|
|
{
|
|
if (!$this->isValidFileName($fileName)) {
|
|
throw new \InvalidArgumentException("Invalid file name: $fileName");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function requireValidFilePath(string $filePath): void
|
|
{
|
|
if (!$this->isValidFilePath($filePath)) {
|
|
throw new \InvalidArgumentException("Invalid file path: $filePath");
|
|
}
|
|
}
|
|
|
|
public function isFileInStore(string $fileName): bool
|
|
{
|
|
// Check if the file exists in the store
|
|
return self::doesObjectExist($fileName);
|
|
}
|
|
|
|
public function download(string $file): string
|
|
{
|
|
$path = '/tmp/' . $file;
|
|
$result = self::getS3Client()->getObject([
|
|
'Bucket' => self::getBucket(),
|
|
'Key' => $file,
|
|
'SaveAs' => $path
|
|
]);
|
|
return $path;
|
|
}
|
|
|
|
public function generateDirectDownloadUrl(string $fileName): string
|
|
{
|
|
// Generate a direct download URL for the given file name
|
|
return 'https://api.truckwash.dk:4433/files/' . $fileName;
|
|
}
|
|
} |