file paths
This commit is contained in:
@@ -2,7 +2,8 @@ export function imgurl(channel, record) {
|
|||||||
if (record._file.mime === "image/svg+xml") {
|
if (record._file.mime === "image/svg+xml") {
|
||||||
return fileurl(channel, record);
|
return fileurl(channel, record);
|
||||||
}
|
}
|
||||||
return channel.disks[record._file.disk] + `/thumbs/${record._file.path}`;
|
const pathAr = record._file.path.split("/");
|
||||||
|
return channel.disks[record._file.disk] + `/${pathAr[0]}/thumbs/${pathAr[1]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fileurl(channel, record) {
|
export function fileurl(channel, record) {
|
||||||
@@ -17,7 +18,8 @@ export function htmlurl(channel, record, preset) {
|
|||||||
if (record._file.width > 0) {
|
if (record._file.width > 0) {
|
||||||
let presetUrl = url;
|
let presetUrl = url;
|
||||||
if (preset) {
|
if (preset) {
|
||||||
presetUrl = channel.disks[record._file.disk] + `/templates/${preset}/${record._file.path}`;
|
const pathAr = record._file.path.split("/");
|
||||||
|
presetUrl = channel.disks[record._file.disk] + `/${pathAr[0]}/templates/${preset}/${pathAr[1]}`;
|
||||||
}
|
}
|
||||||
html = `<img src="${presetUrl}" alt="${record._file.path}" />`
|
html = `<img src="${presetUrl}" alt="${record._file.path}" />`
|
||||||
} else if (record._file.mime === "image/svg+xml") {
|
} else if (record._file.mime === "image/svg+xml") {
|
||||||
|
|||||||
@@ -44,8 +44,11 @@ class RebuildThumbnails extends Command
|
|||||||
$this->info("Rebuilding thumbnails for ". $schema->name);
|
$this->info("Rebuilding thumbnails for ". $schema->name);
|
||||||
$records = $this->query->filter(["schema" => $schema->name])->run()->records;
|
$records = $this->query->filter(["schema" => $schema->name])->run()->records;
|
||||||
$disk = $this->fileService->loadDisk($schema->disk);
|
$disk = $this->fileService->loadDisk($schema->disk);
|
||||||
|
$disk->deleteDirectory($schema->path."/templates");
|
||||||
|
$disk->deleteDirectory($schema->path."/thumbs");
|
||||||
foreach ($records as $record) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use Lucent\Database\Database;
|
|||||||
use Lucent\LucentException;
|
use Lucent\LucentException;
|
||||||
use Lucent\Record\FileData as RecordFile;
|
use Lucent\Record\FileData as RecordFile;
|
||||||
use Lucent\Record\QueryRecord;
|
use Lucent\Record\QueryRecord;
|
||||||
|
use Lucent\Record\Record;
|
||||||
use Lucent\Schema\FilesSchema;
|
use Lucent\Schema\FilesSchema;
|
||||||
use Lucent\Schema\Schema;
|
use Lucent\Schema\Schema;
|
||||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||||
@@ -83,7 +84,7 @@ class FileService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isImage($mimetype)) {
|
if ($this->isImage($mimetype)) {
|
||||||
$this->createTemplates($disk, $path);
|
$this->createTemplates($disk, $schema->path, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
|
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
|
||||||
@@ -136,10 +137,11 @@ class FileService
|
|||||||
return $record->id ?? "";
|
return $record->id ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createTemplates(Filesystem $disk, string $path): void
|
|
||||||
|
public function createTemplates(Filesystem $disk, string $path, string $filename): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$originalImage = $this->imageManager->read($disk->get($path));
|
$originalImage = $this->imageManager->read($disk->get($path . "/" . $filename));
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->logger->error($exception->getMessage());
|
$this->logger->error($exception->getMessage());
|
||||||
return;
|
return;
|
||||||
@@ -156,12 +158,12 @@ class FileService
|
|||||||
);
|
);
|
||||||
|
|
||||||
$image = $originalImage->modify(new $filterClass);
|
$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)));
|
$disk->put($templateUri, $image->encode(new WebpEncoder(75)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$thumbDir = "thumbs/" . $path;
|
$thumbDir = "$path/thumbs/" . $filename;
|
||||||
|
|
||||||
$image = $originalImage->cover(300, 300);
|
$image = $originalImage->cover(300, 300);
|
||||||
$disk->put($thumbDir, $image->encode(new WebpEncoder(quality: 75)));
|
$disk->put($thumbDir, $image->encode(new WebpEncoder(quality: 75)));
|
||||||
|
|||||||
+2
-2
@@ -57,8 +57,8 @@ if (!function_exists('lucent_file')) {
|
|||||||
if (!function_exists('lucent_image')) {
|
if (!function_exists('lucent_image')) {
|
||||||
function lucent_image(\Lucent\Record\QueryRecord $record, string $template): string
|
function lucent_image(\Lucent\Record\QueryRecord $record, string $template): string
|
||||||
{
|
{
|
||||||
$path = $record->_file->path;
|
$filenameAr = explode("/",$record->_file->path);
|
||||||
return app()->make(\Lucent\Channel\ChannelService::class)->channel->disks[$record->_file->disk] . "/templates/$template/$path";
|
return app()->make(\Lucent\Channel\ChannelService::class)->channel->disks[$record->_file->disk] ."/". $filenameAr[0]. "/templates/$template/". $filenameAr[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user