mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Migrate permission away from Jetstream; Moved update user to REST API
This commit is contained in:
committed by
Constantin Graf
parent
12d58ee42c
commit
5d744d70c4
37
app/Rules/Base64ImageRule.php
Normal file
37
app/Rules/Base64ImageRule.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Support\Base64File;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Translation\PotentiallyTranslatedString;
|
||||
|
||||
class Base64ImageRule implements ValidationRule
|
||||
{
|
||||
private const array ALLOWED_MIME_TYPES = [
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param Closure(string): PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! is_string($value)) {
|
||||
$fail(__('validation.string'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$file = Base64File::decode($value);
|
||||
if ($file === null || ! in_array($file['mime_type'], self::ALLOWED_MIME_TYPES, true)) {
|
||||
$fail(__('validation.mimes', ['values' => 'jpg, png']));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user