mirror of
https://github.com/koel/koel
synced 2024-11-14 16:37:28 +00:00
21 lines
527 B
PHP
21 lines
527 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ImageData implements ValidationRule
|
|
{
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$passes = rescue(static function () use ($value) {
|
|
return (bool) preg_match('/data:image\/(jpe?g|png|webp|gif)/i', Str::before($value, ';'));
|
|
}) ?? false;
|
|
|
|
if (!$passes) {
|
|
$fail('Invalid DataURL string');
|
|
}
|
|
}
|
|
}
|