PR #82 made `meta.aspect_ratio` crop Facebook (and already Instagram) feed images at publish time, but the API and MCP surfaces only half-supported it: you couldn't set meta at creation, the value wasn't validated, and responses never returned it. This closes those gaps. - New `AspectRatio` enum is the single source of truth for the allowed ratios (1:1, 4:5, 16:9, original). App/API/MCP requests now validate via `Rule::enum(AspectRatio::class)` — an invalid ratio is rejected everywhere instead of silently center-cropping to square. - API `StorePostRequest` and MCP `CreatePostTool` now accept `platforms.*.meta`; `CreatePost` persists it. MCP create documents `meta` in its schema. - `Api\PostPlatformResource` now exposes `meta`, so API and MCP responses return the aspect_ratio (and other per-platform meta) a client set.
79 lines
2.5 KiB
PHP
79 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api\Post;
|
|
|
|
use App\Enums\PostPlatform\AspectRatio;
|
|
use App\Enums\PostPlatform\ContentType;
|
|
use App\Enums\SocialAccount\Platform;
|
|
use App\Models\SocialAccount;
|
|
use App\Rules\ContentFitsPlatformLimits;
|
|
use App\Rules\ContentTypeMatchesPlatform;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StorePostRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$workspaceId = $this->user()->currentWorkspace->id;
|
|
|
|
return [
|
|
'content' => [
|
|
'nullable',
|
|
'string',
|
|
'max:10000',
|
|
Rule::when(
|
|
$this->filled('scheduled_at'),
|
|
[new ContentFitsPlatformLimits($this->resolveSelectedPlatforms($workspaceId))]
|
|
),
|
|
],
|
|
'media' => ['sometimes', 'array'],
|
|
'platforms' => ['required', 'array', 'min:1'],
|
|
'platforms.*.social_account_id' => [
|
|
'required',
|
|
'uuid',
|
|
Rule::exists('social_accounts', 'id')
|
|
->where('workspace_id', $workspaceId)
|
|
->where('is_active', true),
|
|
],
|
|
'platforms.*.content_type' => [
|
|
'required',
|
|
'string',
|
|
Rule::in(array_column(ContentType::cases(), 'value')),
|
|
new ContentTypeMatchesPlatform,
|
|
],
|
|
'platforms.*.meta' => ['sometimes', 'nullable', 'array'],
|
|
'platforms.*.meta.aspect_ratio' => ['sometimes', 'nullable', 'string', Rule::enum(AspectRatio::class)],
|
|
'scheduled_at' => ['nullable', 'date', 'after:now'],
|
|
'label_ids' => ['sometimes', 'array'],
|
|
'label_ids.*' => [
|
|
'uuid',
|
|
Rule::exists('workspace_labels', 'id')->where('workspace_id', $workspaceId),
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int|string, Platform>
|
|
*/
|
|
private function resolveSelectedPlatforms(string $workspaceId): Collection
|
|
{
|
|
$accountIds = collect($this->input('platforms', []))->pluck('social_account_id')->filter()->all();
|
|
if (empty($accountIds)) {
|
|
return collect();
|
|
}
|
|
|
|
return SocialAccount::query()
|
|
->where('workspace_id', $workspaceId)
|
|
->whereIn('id', $accountIds)
|
|
->pluck('platform', 'id');
|
|
}
|
|
}
|