file paths

This commit is contained in:
2024-10-09 23:36:24 +03:00
parent e9537862ca
commit 986d3420cb
4 changed files with 17 additions and 10 deletions
+4 -1
View File
@@ -44,8 +44,11 @@ class RebuildThumbnails extends Command
$this->info("Rebuilding thumbnails for ". $schema->name);
$records = $this->query->filter(["schema" => $schema->name])->run()->records;
$disk = $this->fileService->loadDisk($schema->disk);
$disk->deleteDirectory($schema->path."/templates");
$disk->deleteDirectory($schema->path."/thumbs");
foreach ($records as $record) {
$this->fileService->createTemplates($disk, $record->_file->path);
$filename = substr($record->_file->path, strlen($schema->path) + 1 , strlen($record->_file->path));
$this->fileService->createTemplates($disk, $schema->path,$filename);
}
}
+7 -5
View File
@@ -16,6 +16,7 @@ use Lucent\Database\Database;
use Lucent\LucentException;
use Lucent\Record\FileData as RecordFile;
use Lucent\Record\QueryRecord;
use Lucent\Record\Record;
use Lucent\Schema\FilesSchema;
use Lucent\Schema\Schema;
use Spatie\ImageOptimizer\OptimizerChainFactory;
@@ -83,7 +84,7 @@ class FileService
}
if ($this->isImage($mimetype)) {
$this->createTemplates($disk, $path);
$this->createTemplates($disk, $schema->path, $filename);
}
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
@@ -136,10 +137,11 @@ class FileService
return $record->id ?? "";
}
public function createTemplates(Filesystem $disk, string $path): void
public function createTemplates(Filesystem $disk, string $path, string $filename): void
{
try {
$originalImage = $this->imageManager->read($disk->get($path));
$originalImage = $this->imageManager->read($disk->get($path . "/" . $filename));
} catch (Exception $exception) {
$this->logger->error($exception->getMessage());
return;
@@ -156,12 +158,12 @@ class FileService
);
$image = $originalImage->modify(new $filterClass);
$templateUri = "/templates/" . (new $filterClass)->name . "/" . $path;
$templateUri = "$path/templates/" . (new $filterClass)->name . "/" . $filename;
$disk->put($templateUri, $image->encode(new WebpEncoder(75)));
};
$thumbDir = "thumbs/" . $path;
$thumbDir = "$path/thumbs/" . $filename;
$image = $originalImage->cover(300, 300);
$disk->put($thumbDir, $image->encode(new WebpEncoder(quality: 75)));
+2 -2
View File
@@ -57,8 +57,8 @@ if (!function_exists('lucent_file')) {
if (!function_exists('lucent_image')) {
function lucent_image(\Lucent\Record\QueryRecord $record, string $template): string
{
$path = $record->_file->path;
return app()->make(\Lucent\Channel\ChannelService::class)->channel->disks[$record->_file->disk] . "/templates/$template/$path";
$filenameAr = explode("/",$record->_file->path);
return app()->make(\Lucent\Channel\ChannelService::class)->channel->disks[$record->_file->disk] ."/". $filenameAr[0]. "/templates/$template/". $filenameAr[1];
}
}