Adds POST /api/posts/{post}/media for direct file (multipart) upload
and renames the existing URL-based flow to /api/posts/{post}/media/from-url
so the path matches HTTP semantics (POST <resource>/media expects a file
body, not JSON URLs).
The multipart action validates type against the post's enabled platforms
(image rejected on TikTok-only posts), enforces per-type size caps, and
reuses Workspace::addMedia + Post::appendMedia. URL-based attaching is
unchanged behaviorally — only the route name and controller method are
renamed for symmetry. The MCP AttachMediaFromUrlTool was already named
correctly and needs no changes; binary upload via MCP is a host-protocol
limitation that no MCP server (including Postiz) supports.
38 lines
906 B
PHP
38 lines
906 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api\Post;
|
|
|
|
use App\Enums\Media\Type as MediaType;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreMediaRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$allowedMimes = [
|
|
...MediaType::Image->allowedMimeTypes(),
|
|
...MediaType::Video->allowedMimeTypes(),
|
|
];
|
|
|
|
return [
|
|
// Use the largest per-type cap as the upper bound; per-type
|
|
// and per-post enforcement happens in the controller.
|
|
'media' => [
|
|
'required',
|
|
'file',
|
|
'max:'.MediaType::Video->maxSizeInKb(),
|
|
'mimetypes:'.implode(',', $allowedMimes),
|
|
],
|
|
];
|
|
}
|
|
}
|