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.
36 lines
914 B
PHP
36 lines
914 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\Api;
|
|
|
|
use App\Models\Post;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* Wraps a Post with the result of an attach-media-from-url operation
|
|
* (counts + list of failed URLs).
|
|
*/
|
|
class PostMediaAttachResource extends JsonResource
|
|
{
|
|
/**
|
|
* @param array{attached: array<int, array<string, mixed>>, failed: array<int, string>} $result
|
|
*/
|
|
public function __construct(Post $post, private readonly array $result)
|
|
{
|
|
parent::__construct($post);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'post' => (new PostResource($this->resource))->resolve(),
|
|
'attached_count' => count($this->result['attached']),
|
|
'failed_urls' => $this->result['failed'],
|
|
];
|
|
}
|
|
}
|