optimizations
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AdminStoreNovaCardAssetPackRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'slug' => ['required', 'string', 'max:140', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/'],
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'description' => ['nullable', 'string', 'max:500'],
|
||||
'type' => ['required', Rule::in(['asset', 'template'])],
|
||||
'preview_image' => ['nullable', 'string', 'max:255'],
|
||||
'manifest_json' => ['nullable', 'array'],
|
||||
'official' => ['sometimes', 'boolean'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'order_num' => ['sometimes', 'integer', 'min:0', 'max:9999'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AdminStoreNovaCardCategoryRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'slug' => ['required', 'string', 'max:120', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/'],
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'description' => ['nullable', 'string', 'max:400'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'order_num' => ['sometimes', 'integer', 'min:0', 'max:9999'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AdminStoreNovaCardChallengeRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'slug' => ['required', 'string', 'max:140', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/'],
|
||||
'title' => ['required', 'string', 'max:140'],
|
||||
'description' => ['nullable', 'string', 'max:1000'],
|
||||
'prompt' => ['nullable', 'string', 'max:1000'],
|
||||
'rules_json' => ['nullable', 'array'],
|
||||
'status' => ['required', Rule::in(['draft', 'active', 'completed', 'archived'])],
|
||||
'official' => ['sometimes', 'boolean'],
|
||||
'featured' => ['sometimes', 'boolean'],
|
||||
'winner_card_id' => ['nullable', 'integer', 'exists:nova_cards,id'],
|
||||
'starts_at' => ['nullable', 'date'],
|
||||
'ends_at' => ['nullable', 'date', 'after_or_equal:starts_at'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AdminStoreNovaCardTemplateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'slug' => ['required', 'string', 'max:120', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/'],
|
||||
'name' => ['required', 'string', 'max:160'],
|
||||
'description' => ['nullable', 'string', 'max:400'],
|
||||
'preview_image' => ['nullable', 'string', 'max:255'],
|
||||
'config_json' => ['required', 'array'],
|
||||
'supported_formats' => ['required', 'array', 'min:1'],
|
||||
'supported_formats.*' => ['string', Rule::in(array_keys((array) config('nova_cards.formats', [])))],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'official' => ['sometimes', 'boolean'],
|
||||
'order_num' => ['sometimes', 'integer', 'min:0', 'max:9999'],
|
||||
];
|
||||
}
|
||||
}
|
||||
40
app/Http/Requests/NovaCards/AdminUpdateNovaCardRequest.php
Normal file
40
app/Http/Requests/NovaCards/AdminUpdateNovaCardRequest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use App\Models\NovaCard;
|
||||
use App\Services\NovaCards\NovaCardPublishModerationService;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AdminUpdateNovaCardRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'status' => ['sometimes', Rule::in([
|
||||
NovaCard::STATUS_DRAFT,
|
||||
NovaCard::STATUS_PROCESSING,
|
||||
NovaCard::STATUS_PUBLISHED,
|
||||
NovaCard::STATUS_HIDDEN,
|
||||
NovaCard::STATUS_REJECTED,
|
||||
])],
|
||||
'moderation_status' => ['sometimes', Rule::in([
|
||||
NovaCard::MOD_PENDING,
|
||||
NovaCard::MOD_APPROVED,
|
||||
NovaCard::MOD_FLAGGED,
|
||||
NovaCard::MOD_REJECTED,
|
||||
])],
|
||||
'disposition' => ['sometimes', 'nullable', Rule::in(array_keys(NovaCardPublishModerationService::DISPOSITION_LABELS))],
|
||||
'featured' => ['sometimes', 'boolean'],
|
||||
'allow_remix' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
86
app/Http/Requests/NovaCards/SaveNovaCardDraftRequest.php
Normal file
86
app/Http/Requests/NovaCards/SaveNovaCardDraftRequest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use App\Models\NovaCard;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SaveNovaCardDraftRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$validation = (array) config('nova_cards.validation', []);
|
||||
|
||||
return [
|
||||
'title' => ['sometimes', 'string', 'min:2', 'max:' . (int) ($validation['title_max'] ?? 120)],
|
||||
'quote_text' => ['sometimes', 'string', 'min:' . (int) ($validation['quote_min'] ?? 3), 'max:' . (int) ($validation['quote_max'] ?? 420)],
|
||||
'quote_author' => ['sometimes', 'nullable', 'string', 'max:160'],
|
||||
'quote_source' => ['sometimes', 'nullable', 'string', 'max:180'],
|
||||
'description' => ['sometimes', 'nullable', 'string', 'max:' . (int) ($validation['description_max'] ?? 500)],
|
||||
'format' => ['sometimes', Rule::in(array_keys((array) config('nova_cards.formats', [])))],
|
||||
'template_id' => ['sometimes', 'nullable', 'integer', 'exists:nova_card_templates,id'],
|
||||
'category_id' => ['sometimes', 'nullable', 'integer', 'exists:nova_card_categories,id'],
|
||||
'background_type' => ['sometimes', Rule::in(['gradient', 'upload', 'template', 'solid'])],
|
||||
'background_image_id' => ['sometimes', 'nullable', 'integer', 'exists:nova_card_backgrounds,id'],
|
||||
'visibility' => ['sometimes', Rule::in([NovaCard::VISIBILITY_PUBLIC, NovaCard::VISIBILITY_UNLISTED, NovaCard::VISIBILITY_PRIVATE])],
|
||||
'allow_download' => ['sometimes', 'boolean'],
|
||||
'allow_remix' => ['sometimes', 'boolean'],
|
||||
'editor_mode_last_used' => ['sometimes', Rule::in(['quick', 'full'])],
|
||||
'tags' => ['sometimes', 'array', 'max:' . (int) ($validation['max_tags'] ?? 8)],
|
||||
'tags.*' => ['string', 'min:2', 'max:32'],
|
||||
'project_json' => ['sometimes', 'array'],
|
||||
'project_json.schema_version' => ['sometimes', 'integer', 'min:1', 'max:9'],
|
||||
'project_json.text_blocks' => ['sometimes', 'array', 'max:' . (int) ($validation['max_text_blocks'] ?? 8)],
|
||||
'project_json.text_blocks.*.key' => ['sometimes', 'string', 'max:40'],
|
||||
'project_json.text_blocks.*.type' => ['sometimes', Rule::in(['title', 'quote', 'author', 'source', 'body', 'caption'])],
|
||||
'project_json.text_blocks.*.text' => ['sometimes', 'nullable', 'string', 'max:' . (int) ($validation['quote_max'] ?? 420)],
|
||||
'project_json.text_blocks.*.enabled' => ['sometimes', 'boolean'],
|
||||
'project_json.assets.pack_ids' => ['sometimes', 'array'],
|
||||
'project_json.assets.pack_ids.*' => ['integer'],
|
||||
'project_json.assets.template_pack_ids' => ['sometimes', 'array'],
|
||||
'project_json.assets.template_pack_ids.*' => ['integer'],
|
||||
'project_json.assets.items' => ['sometimes', 'array', 'max:' . (int) ($validation['max_asset_items'] ?? 12)],
|
||||
'project_json.assets.items.*.asset_key' => ['sometimes', 'string', 'max:80'],
|
||||
'project_json.assets.items.*.label' => ['sometimes', 'string', 'max:120'],
|
||||
'project_json.assets.items.*.glyph' => ['sometimes', 'string', 'max:4'],
|
||||
'project_json.layout.alignment' => ['sometimes', Rule::in((array) ($validation['allowed_alignments'] ?? ['left', 'center', 'right']))],
|
||||
'project_json.layout.layout' => ['sometimes', Rule::in((array) ($validation['allowed_layouts'] ?? []))],
|
||||
'project_json.layout.position' => ['sometimes', Rule::in((array) ($validation['allowed_positions'] ?? []))],
|
||||
'project_json.layout.padding' => ['sometimes', Rule::in((array) ($validation['allowed_padding_presets'] ?? []))],
|
||||
'project_json.layout.max_width' => ['sometimes', Rule::in((array) ($validation['allowed_max_widths'] ?? []))],
|
||||
'project_json.typography.font_preset' => ['sometimes', Rule::in(array_keys((array) config('nova_cards.font_presets', [])))],
|
||||
'project_json.typography.quote_size' => ['sometimes', 'integer', 'min:24', 'max:160'],
|
||||
'project_json.typography.author_size' => ['sometimes', 'integer', 'min:12', 'max:72'],
|
||||
'project_json.typography.letter_spacing' => ['sometimes', 'integer', 'min:-2', 'max:12'],
|
||||
'project_json.typography.line_height' => ['sometimes', 'numeric', 'min:0.9', 'max:1.8'],
|
||||
'project_json.typography.shadow_preset' => ['sometimes', Rule::in(array_column((array) config('nova_cards.shadow_presets', []), 'key'))],
|
||||
'project_json.typography.text_color' => ['sometimes', 'regex:/^#(?:[0-9a-fA-F]{3}){1,2}$/'],
|
||||
'project_json.typography.accent_color' => ['sometimes', 'regex:/^#(?:[0-9a-fA-F]{3}){1,2}$/'],
|
||||
'project_json.background.type' => ['sometimes', Rule::in(['gradient', 'upload', 'template', 'solid'])],
|
||||
'project_json.background.gradient_preset' => ['sometimes', Rule::in(array_keys((array) config('nova_cards.gradient_presets', [])))],
|
||||
'project_json.background.gradient_colors' => ['sometimes', 'array', 'min:2', 'max:3'],
|
||||
'project_json.background.gradient_colors.*' => ['regex:/^#(?:[0-9a-fA-F]{3}){1,2}$/'],
|
||||
'project_json.background.solid_color' => ['sometimes', 'regex:/^#(?:[0-9a-fA-F]{3}){1,2}$/'],
|
||||
'project_json.background.overlay_style' => ['sometimes', Rule::in((array) ($validation['allowed_overlay_styles'] ?? []))],
|
||||
'project_json.background.focal_position' => ['sometimes', Rule::in(array_column((array) config('nova_cards.focal_positions', []), 'key'))],
|
||||
'project_json.background.blur_level' => ['sometimes', Rule::in((array) ($validation['allowed_blur_levels'] ?? []))],
|
||||
'project_json.background.opacity' => ['sometimes', Rule::in((array) ($validation['allowed_opacity_levels'] ?? []))],
|
||||
'project_json.source_context.editor_mode' => ['sometimes', Rule::in(['quick', 'full'])],
|
||||
'project_json.decorations' => ['sometimes', 'array', 'max:' . (int) ($validation['max_decorations'] ?? 6)],
|
||||
'project_json.decorations.*.key' => ['sometimes', 'string', 'max:40'],
|
||||
'project_json.decorations.*.glyph' => ['sometimes', 'string', 'max:4'],
|
||||
'project_json.decorations.*.placement' => ['sometimes', 'string', 'max:24'],
|
||||
'project_json.decorations.*.x' => ['sometimes', 'numeric', 'min:0', 'max:1920'],
|
||||
'project_json.decorations.*.y' => ['sometimes', 'numeric', 'min:0', 'max:1920'],
|
||||
'project_json.decorations.*.size' => ['sometimes', 'integer', 'min:2', 'max:120'],
|
||||
];
|
||||
}
|
||||
}
|
||||
34
app/Http/Requests/NovaCards/StoreNovaCardDraftRequest.php
Normal file
34
app/Http/Requests/NovaCards/StoreNovaCardDraftRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use App\Models\NovaCard;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreNovaCardDraftRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => ['nullable', 'string', 'min:2', 'max:' . (int) config('nova_cards.validation.title_max', 120)],
|
||||
'quote_text' => ['nullable', 'string', 'min:' . (int) config('nova_cards.validation.quote_min', 3), 'max:' . (int) config('nova_cards.validation.quote_max', 420)],
|
||||
'quote_author' => ['nullable', 'string', 'max:160'],
|
||||
'quote_source' => ['nullable', 'string', 'max:180'],
|
||||
'description' => ['nullable', 'string', 'max:' . (int) config('nova_cards.validation.description_max', 500)],
|
||||
'format' => ['nullable', Rule::in(array_keys((array) config('nova_cards.formats', [])))],
|
||||
'template_id' => ['nullable', 'integer', 'exists:nova_card_templates,id'],
|
||||
'category_id' => ['nullable', 'integer', 'exists:nova_card_categories,id'],
|
||||
'background_type' => ['nullable', Rule::in(['gradient', 'upload', 'template', 'solid'])],
|
||||
'tags' => ['nullable', 'array', 'max:' . (int) config('nova_cards.validation.max_tags', 8)],
|
||||
'tags.*' => ['string', 'min:2', 'max:32'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\NovaCards;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UploadNovaCardBackgroundRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$bytes = (int) config('nova_cards.validation.max_background_upload_bytes', 8 * 1024 * 1024);
|
||||
$maxKilobytes = (int) ceil($bytes / 1024);
|
||||
|
||||
return [
|
||||
'background' => [
|
||||
'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.');
|
||||
}
|
||||
},
|
||||
'image',
|
||||
'mimes:jpeg,jpg,png,webp',
|
||||
'max:' . $maxKilobytes,
|
||||
Rule::dimensions()->minWidth(480)->minHeight(480),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user