Implement attachments module with CRUD operations and integration points

- Added `attachments` module for creating, reading, updating, and deleting attachments.
- Introduced new classes such as `attachments`, `attachment_store`, `attachment_content`, and `attachment_relation` to handle attachment operations and their relationships.
- Integrated `attachments` features into `db_object_t` for seamless object-attachment interactions.
- Added `attachments_i` interface for standardized attachments module operations.
- Created `attachmentsRoute` for defining endpoints related to attachments.
- Enabled module configuration through `attachments_enabled_c` for attachment management control.
This commit is contained in:
Jeppe Bundgaard
2025-09-22 10:28:22 +02:00
parent 94bbf0a106
commit 33a26cffc5
13 changed files with 567 additions and 0 deletions
@@ -0,0 +1,86 @@
<?php
namespace classes;
use interfaces\minio_uploads_i;
use traits\minio_t;
class attachment_store implements minio_uploads_i
{
use minio_t;
public function __construct()
{
self::setBucket('attachments'); // 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;
}
}