Implement creator studio and upload updates

This commit is contained in:
2026-04-04 10:12:02 +02:00
parent 1da7d3bf88
commit 0b216b7ecd
15107 changed files with 31206 additions and 626514 deletions

View File

@@ -7,7 +7,6 @@ namespace App\Http\Requests\NovaCards;
use Closure;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\Rule;
class UploadNovaCardBackgroundRequest extends FormRequest
{
@@ -26,22 +25,56 @@ class UploadNovaCardBackgroundRequest extends FormRequest
'bail',
'required',
'file',
static function (string $attribute, mixed $value, Closure $fail): void {
if (! $value instanceof UploadedFile) {
return;
}
$path = $value->getRealPath() ?: $value->getPathname();
if (! $value->isValid() || ! is_string($path) || trim($path) === '') {
$fail('The ' . $attribute . ' upload is invalid.');
}
function (string $attribute, mixed $value, Closure $fail): void {
$this->validateUpload($attribute, $value, $fail);
},
'image',
'mimes:jpeg,jpg,png,webp',
'max:' . $maxKilobytes,
Rule::dimensions()->minWidth(480)->minHeight(480),
function (string $attribute, mixed $value, Closure $fail): void {
$this->validateMinimumDimensions($attribute, $value, $fail, 480, 480);
},
],
];
}
private function validateUpload(string $attribute, mixed $value, Closure $fail): void
{
if (! $value instanceof UploadedFile) {
return;
}
$path = $value->getRealPath() ?: $value->getPathname();
if (! $value->isValid() || ! is_string($path) || trim($path) === '' || ! is_readable($path)) {
$fail('The ' . $attribute . ' upload is invalid.');
}
}
private function validateMinimumDimensions(string $attribute, mixed $value, Closure $fail, int $minWidth, int $minHeight): void
{
if (! $value instanceof UploadedFile) {
return;
}
$path = $value->getRealPath() ?: $value->getPathname();
if (! is_string($path) || trim($path) === '' || ! is_readable($path)) {
$fail('The ' . $attribute . ' upload is invalid.');
return;
}
$binary = @file_get_contents($path);
if ($binary === false || $binary === '') {
$fail('The ' . $attribute . ' upload is invalid.');
return;
}
$dimensions = @getimagesizefromstring($binary);
if (! is_array($dimensions) || ($dimensions[0] ?? 0) < $minWidth || ($dimensions[1] ?? 0) < $minHeight) {
$fail(sprintf('The %s must be at least %dx%d pixels.', $attribute, $minWidth, $minHeight));
}
}
}