1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-06 12:02:45 +03:00

Cleaned up logic within ImageRepo

- Moved out extension check to ImageService as that seems more relevant.
- Updated models to use static-style references instead of facade to align with common modern usage within the app.
- Updated custom image_extension validation rule to use shared logic in image service.
This commit is contained in:
Dan Brown
2021-11-01 00:24:42 +00:00
parent 43830a372f
commit c7fea8fe08
5 changed files with 25 additions and 38 deletions

View File

@@ -2,6 +2,7 @@
namespace BookStack\Providers;
use BookStack\Uploads\ImageService;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
@@ -13,9 +14,8 @@ class CustomValidationServiceProvider extends ServiceProvider
public function boot(): void
{
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
$validImageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions);
$extension = strtolower($value->getClientOriginalExtension());
return ImageService::isExtensionSupported($extension);
});
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {