use webp
This commit is contained in:
@@ -37,6 +37,13 @@ class MediaRebuild extends Command
|
|||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
'Replace existing files'
|
'Replace existing files'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->addOption(
|
||||||
|
'all',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'Rebuild all variants'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,8 +54,15 @@ class MediaRebuild extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$replace = $this->option('replace');
|
$replace = $this->option('replace');
|
||||||
|
$all = $this->option('replace');
|
||||||
|
|
||||||
|
$media = [];
|
||||||
|
if ($all === true) {
|
||||||
|
$media = Media::all();
|
||||||
|
} else {
|
||||||
$media = Media::where(['variants' => ''])->orWhere(['variants' => '[]'])->orWhere(['variants' => '{}'])->get();
|
$media = Media::where(['variants' => ''])->orWhere(['variants' => '[]'])->orWhere(['variants' => '{}'])->get();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($media as $medium) {
|
foreach ($media as $medium) {
|
||||||
StoreUploadedFileJob::dispatch($medium, '', $replace)->onQueue('media');
|
StoreUploadedFileJob::dispatch($medium, '', $replace)->onQueue('media');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,9 +128,13 @@ class StoreUploadedFileJob implements ShouldQueue
|
|||||||
$postfix = 'scaled';
|
$postfix = 'scaled';
|
||||||
}
|
}
|
||||||
|
|
||||||
$newFilename = pathinfo($this->media->name, PATHINFO_FILENAME) . "-$postfix." . pathinfo($this->media->name, PATHINFO_EXTENSION);
|
if (is_array($this->media->variants) === true && array_key_exists($postfix, $this->media->variants) === true && Storage::disk($storageDisk)->exists($this->media->variants[$postfix]) === true && $this->replaceExisting === true) {
|
||||||
|
Storage::disk($storageDisk)->delete($this->media->variants[$postfix]);
|
||||||
|
}
|
||||||
|
|
||||||
if (Storage::disk($storageDisk)->exists($newFilename) == false || $this->replaceExisting == true) {
|
$newFilename = pathinfo($this->media->name, PATHINFO_FILENAME) . "-$postfix.webp";
|
||||||
|
|
||||||
|
if (Storage::disk($storageDisk)->exists($newFilename) === false || $this->replaceExisting === true) {
|
||||||
// Get the largest available variant
|
// Get the largest available variant
|
||||||
if ($dimensions[0] >= $size[0] && $dimensions[1] >= $size[1]) {
|
if ($dimensions[0] >= $size[0] && $dimensions[1] >= $size[1]) {
|
||||||
// Store the variant in the variants array
|
// Store the variant in the variants array
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ watch(
|
|||||||
() => form.controls.file.value,
|
() => form.controls.file.value,
|
||||||
(newValue) => {
|
(newValue) => {
|
||||||
fileData.mime_type = (newValue as File).type;
|
fileData.mime_type = (newValue as File).type;
|
||||||
fileData.size = (newValue as File).size.toString();
|
fileData.size = (newValue as File).size;
|
||||||
|
|
||||||
if ((form.controls.title.value as string).length == 0) {
|
if ((form.controls.title.value as string).length == 0) {
|
||||||
form.controls.title.value = (newValue as File).name
|
form.controls.title.value = (newValue as File).name
|
||||||
|
|||||||
Reference in New Issue
Block a user