1
0

Add attachements directly in the filesystem

This commit is contained in:
Richard Dern 2024-04-28 01:28:06 +02:00
parent 495936503d
commit 2bbd15f0f1
2 changed files with 31 additions and 2 deletions

View File

@ -34,14 +34,14 @@ class AttachmentsManager
*/
const Videos = 'videos';
private string $attachmentsDir = 'attachments';
private string $targetForFiles;
private string $metadataFilePath;
private MetadataManager $manager;
private string $attachmentsDir = 'attachments';
private FilesystemAdapter $disk;
private bool $isLoaded = false;

View File

@ -2,9 +2,11 @@
namespace App\Classes\Traits\Repairs;
use App\Classes\AttachmentsManager;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Intervention\Image\Laravel\Facades\Image;
use League\Flysystem\StorageAttributes;
/**
* Trait for AttachmentsManager
@ -18,6 +20,33 @@ private function repairImages()
{
$this->load();
$files = $this->disk->listContents(
sprintf(
'%s/%s/%s',
$this->bundle->getDataDir(),
$this->attachmentsDir,
AttachmentsManager::Images
),
false
)
->filter(fn (StorageAttributes $attributes) => $attributes->isFile())
->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray();
foreach ($files as $file) {
$content = $this->disk->get($file);
$filename = sprintf('%s/%s', AttachmentsManager::Images, pathinfo($file, PATHINFO_BASENAME));
$data = [
'contents' => $content,
'filename' => $filename,
];
$this->disk->delete($file);
$this->add($data);
}
foreach ($this->manager->get('files', []) as $ref => $data) {
$this->repairKnownImage($ref, $data);
}