diff --git a/app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php b/app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php index 61cdddf0e..5fec9f225 100644 --- a/app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php +++ b/app/Filament/Admin/Resources/Eggs/Pages/EditEgg.php @@ -485,18 +485,20 @@ class EditEgg extends EditRecord ], ]); + $normalizedExtension = match ($extension) { + 'svg+xml', 'svg' => 'svg', + 'jpeg', 'jpg' => 'jpg', + 'png' => 'png', + 'webp' => 'webp', + default => throw new Exception(trans('admin/egg.import.unknown_extension')), + }; + $data = @file_get_contents($imageUrl, false, $context, 0, 1048576); // 1024KB if (empty($data)) { throw new Exception(trans('admin/egg.import.invalid_url')); } - $normalizedExtension = match ($extension) { - 'svg+xml' => 'svg', - 'jpeg' => 'jpg', - default => $extension, - }; - Storage::disk('public')->put(Egg::ICON_STORAGE_PATH . "/$egg->uuid.$normalizedExtension", $data); } diff --git a/app/Filament/Admin/Resources/Servers/Pages/EditServer.php b/app/Filament/Admin/Resources/Servers/Pages/EditServer.php index 9b8eac165..4ff388380 100644 --- a/app/Filament/Admin/Resources/Servers/Pages/EditServer.php +++ b/app/Filament/Admin/Resources/Servers/Pages/EditServer.php @@ -121,6 +121,7 @@ class EditServer extends EditRecord ->columnSpan(2) ->alignJustify(), Action::make('uploadIcon') + ->hiddenLabel() ->icon(TablerIcon::PhotoUp) ->tooltip(trans('admin/server.import_image')) ->modal() @@ -1218,18 +1219,20 @@ class EditServer extends EditRecord ], ]); + $normalizedExtension = match ($extension) { + 'svg+xml', 'svg' => 'svg', + 'jpeg', 'jpg' => 'jpg', + 'png' => 'png', + 'webp' => 'webp', + default => throw new Exception(trans('admin/egg.import.unknown_extension')), + }; + $data = @file_get_contents($imageUrl, false, $context, 0, 262144); //256KB if (empty($data)) { - throw new \Exception(trans('admin/egg.import.invalid_url')); + throw new Exception(trans('admin/egg.import.invalid_url')); } - $normalizedExtension = match ($extension) { - 'svg+xml' => 'svg', - 'jpeg' => 'jpg', - default => $extension, - }; - Storage::disk('public')->put(Server::ICON_STORAGE_PATH . "/$server->uuid.$normalizedExtension", $data); } } diff --git a/app/Filament/Server/Pages/Settings.php b/app/Filament/Server/Pages/Settings.php index 86d845f05..9e59f2e8e 100644 --- a/app/Filament/Server/Pages/Settings.php +++ b/app/Filament/Server/Pages/Settings.php @@ -462,18 +462,20 @@ class Settings extends ServerFormPage ], ]); + $normalizedExtension = match ($extension) { + 'svg+xml', 'svg' => 'svg', + 'jpeg', 'jpg' => 'jpg', + 'png' => 'png', + 'webp' => 'webp', + default => throw new Exception(trans('admin/egg.import.unknown_extension')), + }; + $data = @file_get_contents($imageUrl, false, $context, 0, 262144); //256KB if (empty($data)) { - throw new \Exception(trans('admin/egg.import.invalid_url')); + throw new Exception(trans('admin/egg.import.invalid_url')); } - $normalizedExtension = match ($extension) { - 'svg+xml' => 'svg', - 'jpeg' => 'jpg', - default => $extension, - }; - Storage::disk('public')->put(Server::ICON_STORAGE_PATH . "/$server->uuid.$normalizedExtension", $data); } diff --git a/lang/en/admin/egg.php b/lang/en/admin/egg.php index 2632d3836..db5d69d51 100644 --- a/lang/en/admin/egg.php +++ b/lang/en/admin/egg.php @@ -31,6 +31,7 @@ return [ 'no_local_ip' => 'Local IP Addresses are not allowed', 'unsupported_format' => 'Unsupported Format. Supported Formats: :formats', 'invalid_url' => 'The provided URL is invalid', + 'unknown_extension' => 'Unknown image extension', 'image_deleted' => 'Image Deleted', 'no_image' => 'No Image Provided', 'image_updated' => 'Image Updated',