From fdfcc668c3c6d1996d3fc2fd66adbb2c4d321f34 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 18 Aug 2024 10:02:02 +0200 Subject: [PATCH] Change is_media_resizable check to mime type --- resources/views/components/tables/curator-column.blade.php | 2 +- src/Components/Forms/Uploader.php | 2 +- src/Models/Media.php | 2 +- src/Resources/MediaResource.php | 2 +- src/helpers.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/views/components/tables/curator-column.blade.php b/resources/views/components/tables/curator-column.blade.php index 5a2b7574..415ab9b6 100644 --- a/resources/views/components/tables/curator-column.blade.php +++ b/resources/views/components/tables/curator-column.blade.php @@ -41,7 +41,7 @@ $ring . ' ring-white dark:ring-gray-900' => $imageCount > 1, ]) > - @if (\Awcodes\Curator\is_media_resizable($item->ext)) + @if (\Awcodes\Curator\is_media_resizable($item->type)) @php $img_width = $width ? (int)$width : null; $img_height = $height ? (int)$height : null; diff --git a/src/Components/Forms/Uploader.php b/src/Components/Forms/Uploader.php index 5da23755..a3ee422d 100644 --- a/src/Components/Forms/Uploader.php +++ b/src/Components/Forms/Uploader.php @@ -99,7 +99,7 @@ protected function setUp(): void $storeMethod = $component->getVisibility() === 'public' ? 'storePubliclyAs' : 'storeAs'; - if (is_media_resizable($extension)) { + if (is_media_resizable($file->getMimeType())) { if (in_array(config('livewire.temporary_file_upload.disk'), config('curator.cloud_disks')) && config('livewire.temporary_file_upload.directory') !== null) { $content = Storage::disk($component->getDiskName())->get($file->path()); } else { diff --git a/src/Models/Media.php b/src/Models/Media.php index 36b10085..72fafbc4 100644 --- a/src/Models/Media.php +++ b/src/Models/Media.php @@ -95,7 +95,7 @@ protected function fullPath(): Attribute protected function resizable(): Attribute { return Attribute::make( - get: fn () => is_media_resizable($this->ext), + get: fn () => is_media_resizable($this->type), ); } diff --git a/src/Resources/MediaResource.php b/src/Resources/MediaResource.php index 7c9eeada..6ccc6983 100644 --- a/src/Resources/MediaResource.php +++ b/src/Resources/MediaResource.php @@ -113,7 +113,7 @@ public static function form(Form $form): Form }), ]), Forms\Components\Tabs\Tab::make(trans('curator::forms.sections.curation')) - ->visible(fn ($record) => is_media_resizable($record->ext) && config('curator.tabs.display_curation')) + ->visible(fn ($record) => is_media_resizable($record->type) && config('curator.tabs.display_curation')) ->schema([ Forms\Components\Repeater::make('curations') ->label(trans('curator::forms.sections.curation')) diff --git a/src/helpers.php b/src/helpers.php index 1383d914..4731daf3 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -8,9 +8,9 @@ use Illuminate\Support\Str; if (! function_exists('is_media_resizable')) { - function is_media_resizable(string $ext): bool + function is_media_resizable(string $type): bool { - return in_array($ext, ['jpeg', 'jpg', 'png', 'webp', 'bmp']); + return in_array($type, ['image/jpeg', 'image/png','image/gif', 'image/webp', 'image/bmp']); } }