Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Address PR review: stream MCP uploads and close listing gaps.

Paulo Castellanob28b18ef7282
diff --git a/app/Actions/SocialAccount/ListDiscordChannels.php b/app/Actions/SocialAccount/ListDiscordChannels.php
new file mode 100644
index 000000000..9e0cebf32
--- /dev/null
+++ b/app/Actions/SocialAccount/ListDiscordChannels.php
@@ -0,0 +1,19 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Actions\SocialAccount;
+
+use App\Models\SocialAccount;
+use App\Services\Social\Discord\DiscordClient;
+
+class ListDiscordChannels
+{
+ /**
+ * @return list<array{id: string, name: string}>
+ */
+ public static function execute(SocialAccount $account): array
+ {
+ return app(DiscordClient::class)->channels((string) $account->platform_user_id);
+ }
+}
diff --git a/app/Http/Controllers/Api/SocialAccountController.php b/app/Http/Controllers/Api/SocialAccountController.php
index bc4cf4c58..29b99e8d2 100644
--- a/app/Http/Controllers/Api/SocialAccountController.php
+++ b/app/Http/Controllers/Api/SocialAccountController.php
@@ -4,9 +4,14 @@ declare(strict_types=1);
namespace App\Http\Controllers\Api;
+use App\Actions\SocialAccount\ListDiscordChannels;
use App\Actions\SocialAccount\ListPinterestBoards;
use App\Actions\SocialAccount\ToggleSocialAccount;
use App\Enums\SocialAccount\Platform;
+use App\Exceptions\PlatformUnavailableException;
+use App\Exceptions\Social\ErrorCategory;
+use App\Exceptions\Social\PinterestPublishException;
+use App\Exceptions\TokenExpiredException;
use App\Http\Resources\Api\SocialAccountResource;
use App\Models\SocialAccount;
use Illuminate\Http\JsonResponse;
@@ -53,8 +58,57 @@ class SocialAccountController extends Controller
);
}
- return response()->json([
- 'boards' => ListPinterestBoards::execute($account),
- ]);
+ try {
+ return response()->json([
+ 'boards' => ListPinterestBoards::execute($account),
+ ]);
+ } catch (TokenExpiredException $e) {
+ return response()->json(
+ ['message' => $e->getMessage()],
+ Response::HTTP_UNAUTHORIZED,
+ );
+ } catch (PinterestPublishException $e) {
+ return response()->json(
+ ['message' => $e->userMessage],
+ $this->statusForPinterestCategory($e->category),
+ );
+ }
+ }
+
+ public function channels(Request $request, SocialAccount $account): JsonResponse
+ {
+ if ($account->workspace_id !== $request->user()->currentWorkspace->id) {
+ return response()->json(
+ ['message' => 'Account not found.'],
+ Response::HTTP_NOT_FOUND,
+ );
+ }
+
+ if ($account->platform !== Platform::Discord) {
+ return response()->json(
+ ['message' => 'Channels are only available for Discord accounts.'],
+ Response::HTTP_UNPROCESSABLE_ENTITY,
+ );
+ }
+
+ try {
+ return response()->json([
+ 'channels' => ListDiscordChannels::execute($account),
+ ]);
+ } catch (PlatformUnavailableException $e) {
+ return response()->json(
+ ['message' => $e->getMessage()],
+ Response::HTTP_BAD_GATEWAY,
+ );
+ }
+ }
+
+ private function statusForPinterestCategory(ErrorCategory $category): int
+ {
+ return match ($category) {
+ ErrorCategory::RateLimit => Response::HTTP_TOO_MANY_REQUESTS,
+ ErrorCategory::Permission => Response::HTTP_FORBIDDEN,
+ default => Response::HTTP_BAD_GATEWAY,
+ };
}
}
diff --git a/app/Http/Controllers/Api/UploadController.php b/app/Http/Controllers/Api/UploadController.php
index e6104975c..253e34973 100644
--- a/app/Http/Controllers/Api/UploadController.php
+++ b/app/Http/Controllers/Api/UploadController.php
@@ -35,9 +35,22 @@ class UploadController extends Controller
}
$workspace = Workspace::findOrFail((string) $request->query('workspace_id'));
+ $file = $request->file('media');
+ $path = $file->getRealPath();
- $media = DB::transaction(function () use ($workspace, $request, $token): Media {
- $media = $workspace->addMedia($request->file('media'), 'assets');
+ // Stream from PHP's temp upload path — do not load the whole file into
+ // memory (addMedia() uses file_get_contents; videos can be up to 1GB).
+ if ($path === false) {
+ abort(Response::HTTP_UNPROCESSABLE_ENTITY, 'Unable to read uploaded file.');
+ }
+
+ $media = DB::transaction(function () use ($workspace, $file, $path, $token): Media {
+ $media = $workspace->addMediaFromPath(
+ $path,
+ $file->getClientOriginalName(),
+ 'assets',
+ mimeType: (string) $file->getMimeType(),
+ );
$media->upload_token = $token;
$media->save();
diff --git a/app/Mcp/Servers/TryPostServer.php b/app/Mcp/Servers/TryPostServer.php
index 5f661dfbc..e9f709a20 100644
--- a/app/Mcp/Servers/TryPostServer.php
+++ b/app/Mcp/Servers/TryPostServer.php
@@ -27,6 +27,7 @@ use App\Mcp\Tools\Signature\CreateSignatureTool;
use App\Mcp\Tools\Signature\DeleteSignatureTool;
use App\Mcp\Tools\Signature\ListSignaturesTool;
use App\Mcp\Tools\Signature\UpdateSignatureTool;
+use App\Mcp\Tools\SocialAccount\ListDiscordChannelsTool;
use App\Mcp\Tools\SocialAccount\ListPinterestBoardsTool;
use App\Mcp\Tools\SocialAccount\ListSocialAccountsTool;
use App\Mcp\Tools\SocialAccount\ToggleSocialAccountTool;
@@ -75,6 +76,7 @@ class TryPostServer extends Server
// Social Accounts
ListSocialAccountsTool::class,
ListPinterestBoardsTool::class,
+ ListDiscordChannelsTool::class,
ToggleSocialAccountTool::class,
// Workspace
diff --git a/app/Mcp/Tools/Post/CreatePostTool.php b/app/Mcp/Tools/Post/CreatePostTool.php
index c2c61324a..73730b92a 100644
--- a/app/Mcp/Tools/Post/CreatePostTool.php
+++ b/app/Mcp/Tools/Post/CreatePostTool.php
@@ -63,7 +63,7 @@ class CreatePostTool extends Tool
->items($schema->object(fn ($p) => [
'social_account_id' => $p->string()->required()->description('UUID of the connected social account.'),
'content_type' => $p->string()->required()->description('Format for this platform (e.g. linkedin_post, x_post, instagram_feed).'),
- 'meta' => $p->object()->description('Per-platform metadata. Instagram/Facebook: aspect_ratio (1:1|4:5|16:9|original). TikTok: privacy_level (required to publish) + flags (allow_comments, allow_duet, allow_stitch, disclose, brand_content_toggle, brand_organic_toggle, is_aigc, auto_add_music). Pinterest: board_id (required to publish — call ListPinterestBoardsTool first). Discord: channel_id (required to publish), mentions ([{token,label}]), embeds ([{title,description,url,image,color}]).'),
+ 'meta' => $p->object()->description('Per-platform metadata. Instagram/Facebook: aspect_ratio (1:1|4:5|16:9|original). TikTok: privacy_level (required to publish) + flags (allow_comments, allow_duet, allow_stitch, disclose, brand_content_toggle, brand_organic_toggle, is_aigc, auto_add_music). Pinterest: board_id (required to publish — call ListPinterestBoardsTool first). Discord: channel_id (required to publish — call ListDiscordChannelsTool first), mentions ([{token,label}]), embeds ([{title,description,url,image,color}]).'),
]))
->description('Platforms to publish on. Accounts not listed remain available but disabled.'),
];
diff --git a/app/Mcp/Tools/Post/RequestMediaUploadTool.php b/app/Mcp/Tools/Post/RequestMediaUploadTool.php
index 2f1e4b9cc..6585016a2 100644
--- a/app/Mcp/Tools/Post/RequestMediaUploadTool.php
+++ b/app/Mcp/Tools/Post/RequestMediaUploadTool.php
@@ -15,7 +15,7 @@ use Laravel\Mcp\ResponseFactory;
use Laravel\Mcp\Server\Attributes\Description;
use Laravel\Mcp\Server\Tool;
-#[Description('Issue a one-shot signed POST URL that lets the user upload a local file (image, video, or PDF document) directly to this workspace. Size caps match web/API media limits (video up to the configured video max; images and PDFs use their own smaller caps). Returns an upload_token, upload_url, and max_bytes. Hand the URL to the user (e.g. as a curl command with `-F media=@path/to/file`) or to the MCP client. After upload, call AttachMediaFromUploadTool(post_id, upload_token) to attach the result to a post.')]
+#[Description('Issue a one-shot signed POST URL that lets the user upload a local file (image, video, or PDF document) directly to this workspace. Size caps match web/API media limits — see max_bytes_by_type (max_bytes is the overall ceiling, equal to the video cap). Returns an upload_token, upload_url, max_bytes, and max_bytes_by_type. Hand the URL to the user (e.g. as a curl command with `-F media=@path/to/file`) or to the MCP client. After upload, call AttachMediaFromUploadTool(post_id, upload_token) to attach the result to a post.')]
class RequestMediaUploadTool extends Tool
{
public function handle(Request $request): Response|ResponseFactory
@@ -23,8 +23,6 @@ class RequestMediaUploadTool extends Tool
$user = $request->user();
$workspaceId = $user->current_workspace_id;
- // Same ceiling the web/API FormRequests use (largest per-type cap).
- $maxBytes = MediaType::Video->maxSizeInBytes();
$ttlMinutes = (int) config('trypost.media.signed_upload_url_ttl_minutes');
$token = (string) Str::uuid();
@@ -40,7 +38,12 @@ class RequestMediaUploadTool extends Tool
'upload_token' => $token,
'upload_url' => $uploadUrl,
'expires_at' => $expiresAt->toIso8601String(),
- 'max_bytes' => $maxBytes,
+ 'max_bytes' => MediaType::Video->maxSizeInBytes(),
+ 'max_bytes_by_type' => [
+ 'image' => MediaType::Image->maxSizeInBytes(),
+ 'video' => MediaType::Video->maxSizeInBytes(),
+ 'document' => MediaType::Document->maxSizeInBytes(),
+ ],
'field_name' => 'media',
]);
}
diff --git a/app/Mcp/Tools/Post/UpdatePostTool.php b/app/Mcp/Tools/Post/UpdatePostTool.php
index bf2c9cb82..46e643b64 100644
--- a/app/Mcp/Tools/Post/UpdatePostTool.php
+++ b/app/Mcp/Tools/Post/UpdatePostTool.php
@@ -105,7 +105,7 @@ class UpdatePostTool extends Tool
->items($schema->object(fn ($p) => [
'id' => $p->string()->required()->description('UUID of the post_platform row (from get-post-tool / list-posts-tool).'),
'content_type' => $p->string()->description('New content_type for this platform.'),
- 'meta' => $p->object()->description('Per-platform metadata override. Instagram/Facebook: aspect_ratio. TikTok: privacy_level (required to publish) + flags. Pinterest: board_id (required to publish — call ListPinterestBoardsTool first). Discord: channel_id (required to publish), mentions, embeds. Merged with existing meta.'),
+ 'meta' => $p->object()->description('Per-platform metadata override. Instagram/Facebook: aspect_ratio. TikTok: privacy_level (required to publish) + flags. Pinterest: board_id (required to publish — call ListPinterestBoardsTool first). Discord: channel_id (required to publish — call ListDiscordChannelsTool first), mentions, embeds. Merged with existing meta.'),
]))
->description('Platforms to enable for publishing. Any platform NOT listed will be disabled. Pass an empty array to disable all.'),
];
diff --git a/app/Mcp/Tools/SocialAccount/ListDiscordChannelsTool.php b/app/Mcp/Tools/SocialAccount/ListDiscordChannelsTool.php
new file mode 100644
index 000000000..704c4c479
--- /dev/null
+++ b/app/Mcp/Tools/SocialAccount/ListDiscordChannelsTool.php
@@ -0,0 +1,53 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Mcp\Tools\SocialAccount;
+
+use App\Actions\SocialAccount\ListDiscordChannels;
+use App\Enums\SocialAccount\Platform;
+use App\Exceptions\PlatformUnavailableException;
+use App\Models\SocialAccount;
+use Illuminate\Contracts\JsonSchema\JsonSchema;
+use Laravel\Mcp\Request;
+use Laravel\Mcp\Response;
+use Laravel\Mcp\ResponseFactory;
+use Laravel\Mcp\Server\Attributes\Description;
+use Laravel\Mcp\Server\Tool;
+
+#[Description('List Discord text/announcement channels the bot can post to for a connected Discord server. Use the returned channel id as platforms[].meta.channel_id when creating or updating a Discord post (required to publish).')]
+class ListDiscordChannelsTool extends Tool
+{
+ public function handle(Request $request): Response|ResponseFactory
+ {
+ $validated = $request->validate([
+ 'account_id' => ['required', 'string', 'uuid'],
+ ]);
+
+ $account = SocialAccount::where('workspace_id', $request->user()->current_workspace_id)
+ ->find(data_get($validated, 'account_id'));
+
+ if (! $account) {
+ return Response::error('Social account not found.');
+ }
+
+ if ($account->platform !== Platform::Discord) {
+ return Response::error('This tool only works with Discord social accounts.');
+ }
+
+ try {
+ return Response::structured([
+ 'channels' => ListDiscordChannels::execute($account),
+ ]);
+ } catch (PlatformUnavailableException $e) {
+ return Response::error($e->getMessage());
+ }
+ }
+
+ public function schema(JsonSchema $schema): array
+ {
+ return [
+ 'account_id' => $schema->string()->required()->description('The UUID of the connected Discord social account.'),
+ ];
+ }
+}
diff --git a/app/Mcp/Tools/SocialAccount/ListPinterestBoardsTool.php b/app/Mcp/Tools/SocialAccount/ListPinterestBoardsTool.php
index d8dae901a..9a039281c 100644
--- a/app/Mcp/Tools/SocialAccount/ListPinterestBoardsTool.php
+++ b/app/Mcp/Tools/SocialAccount/ListPinterestBoardsTool.php
@@ -6,6 +6,8 @@ namespace App\Mcp\Tools\SocialAccount;
use App\Actions\SocialAccount\ListPinterestBoards;
use App\Enums\SocialAccount\Platform;
+use App\Exceptions\Social\PinterestPublishException;
+use App\Exceptions\TokenExpiredException;
use App\Models\SocialAccount;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
@@ -34,9 +36,15 @@ class ListPinterestBoardsTool extends Tool
return Response::error('This tool only works with Pinterest social accounts.');
}
- return Response::structured([
- 'boards' => ListPinterestBoards::execute($account),
- ]);
+ try {
+ return Response::structured([
+ 'boards' => ListPinterestBoards::execute($account),
+ ]);
+ } catch (TokenExpiredException $e) {
+ return Response::error($e->getMessage());
+ } catch (PinterestPublishException $e) {
+ return Response::error($e->userMessage);
+ }
}
public function schema(JsonSchema $schema): array
diff --git a/app/Models/Traits/HasMedia.php b/app/Models/Traits/HasMedia.php
index da4b39eb8..8c41e0a99 100644
--- a/app/Models/Traits/HasMedia.php
+++ b/app/Models/Traits/HasMedia.php
@@ -16,6 +16,7 @@ use Illuminate\Support\Str;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Encoders\JpegEncoder;
use Intervention\Image\ImageManager;
+use InvalidArgumentException;
use RuntimeException;
trait HasMedia
@@ -109,13 +110,21 @@ trait HasMedia
* Add media from a file path (used for chunked uploads).
* Images are normalized in memory; videos/PDFs are streamed to storage.
*/
- public function addMediaFromPath(string $filePath, string $originalFilename, string $collection = 'default', array $meta = [], ?string $groupId = null): Media
+ public function addMediaFromPath(string $filePath, string $originalFilename, string $collection = 'default', array $meta = [], ?string $groupId = null, ?string $mimeType = null): Media
{
if ($this->isSingleMediaCollection($collection)) {
$this->clearMediaCollection($collection);
}
- $mimeType = mime_content_type($filePath);
+ // Prefer an explicit MIME (e.g. from UploadedFile after FormRequest
+ // validation) — mime_content_type() misclassifies empty test fakes and
+ // some freshly written temps as application/x-empty.
+ $mimeType ??= mime_content_type($filePath) ?: null;
+
+ if ($mimeType === null) {
+ throw new InvalidArgumentException("Unable to determine MIME type for media file: {$filePath}");
+ }
+
$type = $this->getMediaType($mimeType);
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
@@ -239,7 +248,7 @@ trait HasMedia
private function getMediaType(string $mimeType): string
{
return (Type::classify($mimeType)
- ?? throw new \InvalidArgumentException("Unsupported media MIME type: {$mimeType}"))->value;
+ ?? throw new InvalidArgumentException("Unsupported media MIME type: {$mimeType}"))->value;
}
private function getMediaMeta(UploadedFile $file, string $type): array
diff --git a/app/Services/Social/PinterestPublisher.php b/app/Services/Social/PinterestPublisher.php
index 2d97128d0..6efa47b0b 100644
--- a/app/Services/Social/PinterestPublisher.php
+++ b/app/Services/Social/PinterestPublisher.php
@@ -405,7 +405,9 @@ class PinterestPublisher
}
/**
- * Get user's boards for board selection.
+ * Get user's boards for board selection (follows Pinterest bookmark pagination).
+ *
+ * @return list<array<string, mixed>>
*/
public function getBoards(SocialAccount $account): array
{
@@ -413,17 +415,40 @@ class PinterestPublisher
app(ConnectionVerifier::class)->refreshToken($account);
}
- $response = $this->socialHttp()->withToken($account->access_token)
- ->get($this->baseUrl.'/boards', [
- 'page_size' => 100,
- ]);
+ $boards = [];
+ $bookmark = null;
+ $maxPages = 20;
- if ($response->failed()) {
- Log::error('Pinterest get boards failed', ['body' => $this->redactResponseBody($response->body())]);
- $this->handleApiError($response);
+ for ($page = 0; $page < $maxPages; $page++) {
+ $query = ['page_size' => 100];
+
+ if (filled($bookmark)) {
+ $query['bookmark'] = $bookmark;
+ }
+
+ $response = $this->socialHttp()->withToken($account->access_token)
+ ->get($this->baseUrl.'/boards', $query);
+
+ if ($response->failed()) {
+ Log::error('Pinterest get boards failed', ['body' => $this->redactResponseBody($response->body())]);
+ $this->handleApiError($response);
+ }
+
+ $payload = $response->json() ?? [];
+ $items = data_get($payload, 'items', []);
+
+ if (is_array($items) && $items !== []) {
+ array_push($boards, ...$items);
+ }
+
+ $bookmark = data_get($payload, 'bookmark');
+
+ if (blank($bookmark)) {
+ break;
+ }
}
- return $response->json()['items'] ?? [];
+ return $boards;
}
private function handleApiError(Response $response): never
diff --git a/config/trypost.php b/config/trypost.php
index 3196567ec..f41bc29b9 100644
--- a/config/trypost.php
+++ b/config/trypost.php
@@ -58,6 +58,9 @@ return [
|
| signed_upload_url_ttl_minutes controls the temporary signed POST URL
| issued for api.uploads.store (MCP / direct upload flow).
+ | MEDIA_SIGNED_UPLOAD_URL_TTL_MINUTES is preferred; MCP_UPLOAD_URL_TTL_MINUTES
+ | remains as a legacy fallback. MCP_UPLOAD_MAX_SIZE_MB was removed — size
+ | caps come from max_size_mb above (uploads stream to storage).
|
*/
@@ -68,7 +71,7 @@ return [
// LinkedIn caps document (PDF carousel) uploads at 100MB.
'document' => (int) env('MEDIA_DOCUMENT_MAX_SIZE_MB', 100),
],
- 'signed_upload_url_ttl_minutes' => (int) env('MEDIA_SIGNED_UPLOAD_URL_TTL_MINUTES', 15),
+ 'signed_upload_url_ttl_minutes' => (int) (env('MEDIA_SIGNED_UPLOAD_URL_TTL_MINUTES') ?? env('MCP_UPLOAD_URL_TTL_MINUTES', 15)),
],
/*
diff --git a/resources/js/composables/useMediaRules.ts b/resources/js/composables/useMediaRules.ts
index 60d11898d..089f71cf3 100644
--- a/resources/js/composables/useMediaRules.ts
+++ b/resources/js/composables/useMediaRules.ts
@@ -25,28 +25,28 @@ const MB = 1024 * 1024;
const GB = 1024 * MB;
/**
- * Client-side media constraints that are not duration caps.
- * Video duration comes from ContentType::mediaRulesForFrontend() via
- * Inertia shared once-props (see contentTypeMediaRules).
+ * Client-side media constraints. Duration values here are fallbacks when
+ * Inertia shared contentTypeMediaRules has not synced yet; once synced,
+ * ContentType::maxVideoDurationSec() wins via withSharedDuration().
*/
const CONTENT_TYPE_RULES: Record<string, MediaRules> = {
// Instagram
instagram_feed: {
maxFiles: 10, acceptImages: true, acceptVideos: true, requiresMedia: true,
acceptsGif: false,
- maxImageBytes: 8 * MB, maxVideoBytes: 100 * MB,
+ maxImageBytes: 8 * MB, maxVideoBytes: 100 * MB, maxVideoDurationSec: 60,
aspectRatioMin: 0.8, aspectRatioMax: 1.91,
},
instagram_reel: {
maxFiles: 1, acceptImages: false, acceptVideos: true, requiresMedia: true,
acceptsGif: false,
- maxVideoBytes: 1 * GB,
+ maxVideoBytes: 1 * GB, maxVideoDurationSec: 15 * 60,
aspectRatioMin: 0.5, aspectRatioMax: 0.6,
},
instagram_story: {
maxFiles: 1, acceptImages: true, acceptVideos: true, requiresMedia: true,
acceptsGif: false,
- maxImageBytes: 8 * MB, maxVideoBytes: 100 * MB,
+ maxImageBytes: 8 * MB, maxVideoBytes: 100 * MB, maxVideoDurationSec: 60,
aspectRatioMin: 0.5, aspectRatioMax: 0.6, autoFitsImage: true,
},
@@ -54,18 +54,18 @@ const CONTENT_TYPE_RULES: Record<string, MediaRules> = {
facebook_post: {
maxFiles: 10, acceptImages: true, acceptVideos: true, requiresMedia: false,
acceptsGif: false,
- maxImageBytes: 4 * MB, maxVideoBytes: 10 * GB,
+ maxImageBytes: 4 * MB, maxVideoBytes: 10 * GB, maxVideoDurationSec: 240 * 60,
},
facebook_reel: {
maxFiles: 1, acceptImages: false, acceptVideos: true, requiresMedia: true,
acceptsGif: false,
- maxVideoBytes: 1 * GB,
+ maxVideoBytes: 1 * GB, maxVideoDurationSec: 90,
aspectRatioMin: 0.5, aspectRatioMax: 0.6,
},
facebook_story: {
maxFiles: 1, acceptImages: false, acceptVideos: true, requiresMedia: true,
acceptsGif: false,
- maxVideoBytes: 1 * GB,
+ maxVideoBytes: 1 * GB, maxVideoDurationSec: 60,
aspectRatioMin: 0.5, aspectRatioMax: 0.6,
},
@@ -75,12 +75,12 @@ const CONTENT_TYPE_RULES: Record<string, MediaRules> = {
linkedin_post: {
maxFiles: 10, acceptImages: true, acceptVideos: true, acceptDocuments: true,
requiresMedia: false, acceptsGif: false, forbidsMixedMedia: true,
- maxImageBytes: 5 * MB, maxVideoBytes: 5 * GB, maxDocumentBytes: 100 * MB,
+ maxImageBytes: 5 * MB, maxVideoBytes: 5 * GB, maxVideoDurationSec: 10 * 60, maxDocumentBytes: 100 * MB,
},
linkedin_page_post: {
maxFiles: 10, acceptImages: true, acceptVideos: true, acceptDocuments: true,
requiresMedia: false, acceptsGif: false, forbidsMixedMedia: true,
- maxImageBytes: 5 * MB, maxVideoBytes: 5 * GB, maxDocumentBytes: 100 * MB,
+ maxImageBytes: 5 * MB, maxVideoBytes: 5 * GB, maxVideoDurationSec: 10 * 60, maxDocumentBytes: 100 * MB,
},
// TikTok
@@ -98,7 +98,7 @@ const CONTENT_TYPE_RULES: Record<string, MediaRules> = {
youtube_short: {
maxFiles: 1, acceptImages: false, acceptVideos: true, requiresMedia: true,
acceptsGif: false,
- maxVideoBytes: 256 * GB,
+ maxVideoBytes: 256 * GB, maxVideoDurationSec: 3 * 60,
aspectRatioMin: 0.5, aspectRatioMax: 0.6,
},
@@ -111,7 +111,7 @@ const CONTENT_TYPE_RULES: Record<string, MediaRules> = {
pinterest_video_pin: {
maxFiles: 1, acceptImages: false, acceptVideos: true, requiresMedia: true,
acceptsGif: false,
- maxVideoBytes: 2 * GB,
+ maxVideoBytes: 2 * GB, maxVideoDurationSec: 15 * 60,
},
pinterest_carousel: {
maxFiles: 5, minFiles: 2, acceptImages: true, acceptVideos: false, requiresMedia: true,
@@ -123,14 +123,14 @@ const CONTENT_TYPE_RULES: Record<string, MediaRules> = {
x_post: {
maxFiles: 4, acceptImages: true, acceptVideos: true, requiresMedia: false,
acceptsGif: true,
- maxImageBytes: 5 * MB, maxVideoBytes: 512 * MB,
+ maxImageBytes: 5 * MB, maxVideoBytes: 512 * MB, maxVideoDurationSec: 140,
},
// Threads
threads_post: {
maxFiles: 10, acceptImages: true, acceptVideos: true, requiresMedia: false,
acceptsGif: false,
- maxImageBytes: 8 * MB, maxVideoBytes: 1 * GB,
+ maxImageBytes: 8 * MB, maxVideoBytes: 1 * GB, maxVideoDurationSec: 5 * 60,
},
// Bluesky — accepts GIF; tight image size (auto-resized by backend).
@@ -138,7 +138,7 @@ const CONTENT_TYPE_RULES: Record<string, MediaRules> = {
bluesky_post: {
maxFiles: 4, acceptImages: true, acceptVideos: true, requiresMedia: false,
acceptsGif: true, forbidsMixedMedia: true,
- maxVideoBytes: 100 * MB,
+ maxVideoBytes: 100 * MB, maxVideoDurationSec: 60,
},
// Mastodon — accepts GIF
@@ -158,15 +158,23 @@ const DEFAULT_RULES: MediaRules = {
};
const withSharedDuration = (contentType: string, rules: MediaRules): MediaRules => {
- const maxVideoDurationSec = maxVideoDurationSecFor(contentType);
+ const shared = maxVideoDurationSecFor(contentType);
- if (maxVideoDurationSec === undefined) {
+ // Cache not synced yet — keep local hardcoded fallbacks.
+ if (shared === undefined) {
return rules;
}
+ // Explicitly unlimited / dynamic on the server (e.g. TikTok).
+ if (shared === null) {
+ const { maxVideoDurationSec: _ignored, ...rest } = rules;
+
+ return rest;
+ }
+
return {
...rules,
- maxVideoDurationSec,
+ maxVideoDurationSec: shared,
};
};
diff --git a/resources/js/lib/contentTypeMediaRules.ts b/resources/js/lib/contentTypeMediaRules.ts
index 5ecb541cf..8742bd767 100644
--- a/resources/js/lib/contentTypeMediaRules.ts
+++ b/resources/js/lib/contentTypeMediaRules.ts
@@ -16,8 +16,22 @@ export const syncContentTypeMediaRules = (page: Page): void => {
}
};
-export const maxVideoDurationSecFor = (contentType: string): number | undefined => {
- const seconds = cachedRules?.[contentType]?.max_video_duration_sec;
+/**
+ * Shared Inertia duration for a content type.
+ * - `undefined` — cache not synced yet (or unknown type): keep local fallbacks
+ * - `null` — explicitly unlimited / dynamic (e.g. TikTok)
+ * - `number` — hard cap in seconds from ContentType::maxVideoDurationSec()
+ */
+export const maxVideoDurationSecFor = (contentType: string): number | null | undefined => {
+ if (cachedRules === null) {
+ return undefined;
+ }
+
+ const rule = cachedRules[contentType];
+
+ if (rule === undefined) {
+ return undefined;
+ }
- return typeof seconds === 'number' ? seconds : undefined;
+ return rule.max_video_duration_sec;
};
diff --git a/routes/api.php b/routes/api.php
index 85a86b44d..21828742d 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -53,6 +53,9 @@ Route::middleware(['auth:api', 'workspace.token', 'throttle:api'])->group(functi
Route::get('/social-accounts/{account}/boards', [SocialAccountController::class, 'boards'])
->middleware('throttle:60,1')
->name('api.social-accounts.boards');
+ Route::get('/social-accounts/{account}/channels', [SocialAccountController::class, 'channels'])
+ ->middleware('throttle:60,1')
+ ->name('api.social-accounts.channels');
// API Keys
Route::get('/api-keys', [ApiKeyController::class, 'index'])->name('api.api-keys.index');
diff --git a/tests/Feature/Api/DiscordChannelsApiTest.php b/tests/Feature/Api/DiscordChannelsApiTest.php
new file mode 100644
index 000000000..adefb1fd4
--- /dev/null
+++ b/tests/Feature/Api/DiscordChannelsApiTest.php
@@ -0,0 +1,94 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Enums\SocialAccount\Platform;
+use App\Models\SocialAccount;
+use App\Models\Workspace;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Http;
+
+beforeEach(function () {
+ Cache::flush();
+ config([
+ 'trypost.platforms.discord.bot_token' => 'BOTTOKEN',
+ 'services.discord.client_id' => '999000111',
+ ]);
+
+ $result = createApiTestToken();
+ $this->user = $result['user'];
+ $this->workspace = $result['workspace'];
+ $this->plainToken = $result['plain_token'];
+});
+
+it('lists discord channels for a connected account', function () {
+ $account = SocialAccount::factory()->discord()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'platform_user_id' => '111222333',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.discord.api').'/guilds/111222333/channels' => Http::response([
+ ['id' => '1', 'name' => 'general', 'type' => 0],
+ ['id' => '2', 'name' => 'voice', 'type' => 2],
+ ['id' => '3', 'name' => 'news', 'type' => 5],
+ ], 200),
+ config('trypost.platforms.discord.api').'/guilds/111222333/roles' => Http::response([
+ ['id' => '111222333', 'name' => '@everyone', 'permissions' => '3072'],
+ ], 200),
+ config('trypost.platforms.discord.api').'/guilds/111222333/members/999000111' => Http::response(['roles' => []], 200),
+ ]);
+
+ $response = $this->getJson(route('api.social-accounts.channels', $account), [
+ 'Authorization' => "Bearer {$this->plainToken}",
+ ]);
+
+ $response->assertOk();
+ $response->assertExactJson([
+ 'channels' => [
+ ['id' => '1', 'name' => 'general'],
+ ['id' => '3', 'name' => 'news'],
+ ],
+ ]);
+});
+
+it('returns bad gateway when discord channel lookup fails', function () {
+ $account = SocialAccount::factory()->discord()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'platform_user_id' => '111222333',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.discord.api').'/guilds/111222333/channels' => Http::response('upstream down', 500),
+ ]);
+
+ $this->getJson(route('api.social-accounts.channels', $account), [
+ 'Authorization' => "Bearer {$this->plainToken}",
+ ])
+ ->assertStatus(502)
+ ->assertJsonPath('message', 'Discord channel lookup failed (500).');
+});
+
+it('rejects channels listing for non-discord accounts', function () {
+ $account = SocialAccount::factory()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'platform' => Platform::LinkedIn,
+ ]);
+
+ $this->getJson(route('api.social-accounts.channels', $account), [
+ 'Authorization' => "Bearer {$this->plainToken}",
+ ])
+ ->assertUnprocessable()
+ ->assertJsonPath('message', 'Channels are only available for Discord accounts.');
+});
+
+it('cannot list channels for an account from another workspace', function () {
+ $otherWorkspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->discord()->create([
+ 'workspace_id' => $otherWorkspace->id,
+ ]);
+
+ $this->getJson(route('api.social-accounts.channels', $account), [
+ 'Authorization' => "Bearer {$this->plainToken}",
+ ])->assertNotFound();
+});
diff --git a/tests/Feature/Api/PinterestBoardsApiTest.php b/tests/Feature/Api/PinterestBoardsApiTest.php
index 01967708c..8817b6e5a 100644
--- a/tests/Feature/Api/PinterestBoardsApiTest.php
+++ b/tests/Feature/Api/PinterestBoardsApiTest.php
@@ -42,6 +42,63 @@ it('lists pinterest boards for a connected account', function () {
]);
});
+it('returns an empty boards list when pinterest has none', function () {
+ $account = SocialAccount::factory()->pinterest()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'access_token' => 'pinterest-token',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.pinterest.api').'/boards*' => Http::response([
+ 'items' => [],
+ ], 200),
+ ]);
+
+ $this->getJson(route('api.social-accounts.boards', $account), [
+ 'Authorization' => "Bearer {$this->plainToken}",
+ ])
+ ->assertOk()
+ ->assertExactJson(['boards' => []]);
+});
+
+it('returns unauthorized when the pinterest token is expired', function () {
+ $account = SocialAccount::factory()->pinterest()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'access_token' => 'expired-token',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.pinterest.api').'/boards*' => Http::response([
+ 'message' => 'Access token has expired or been revoked',
+ ], 401),
+ ]);
+
+ $this->getJson(route('api.social-accounts.boards', $account), [
+ 'Authorization' => "Bearer {$this->plainToken}",
+ ])
+ ->assertUnauthorized()
+ ->assertJsonPath('message', 'Access token has expired or been revoked');
+});
+
+it('returns bad gateway when pinterest is unavailable', function () {
+ $account = SocialAccount::factory()->pinterest()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'access_token' => 'pinterest-token',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.pinterest.api').'/boards*' => Http::response([
+ 'message' => 'Internal error',
+ ], 500),
+ ]);
+
+ $this->getJson(route('api.social-accounts.boards', $account), [
+ 'Authorization' => "Bearer {$this->plainToken}",
+ ])
+ ->assertStatus(502)
+ ->assertJsonPath('message', 'Pinterest server error. Please try again.');
+});
+
it('rejects boards listing for non-pinterest accounts', function () {
$account = SocialAccount::factory()->create([
'workspace_id' => $this->workspace->id,
diff --git a/tests/Feature/Api/UploadControllerTest.php b/tests/Feature/Api/UploadControllerTest.php
index 8ac2cf9ec..9fa48ebe3 100644
--- a/tests/Feature/Api/UploadControllerTest.php
+++ b/tests/Feature/Api/UploadControllerTest.php
@@ -129,6 +129,35 @@ test('rejects an image larger than the image media cap even when under the video
expect(Media::where('upload_token', $token)->exists())->toBeFalse();
});
+test('rejects a document larger than the document media cap even when under the video ceiling', function () {
+ config([
+ 'trypost.media.max_size_mb.document' => 1,
+ 'trypost.media.max_size_mb.video' => 1024,
+ ]);
+
+ $token = (string) Str::uuid();
+ $file = UploadedFile::fake()->create('big.pdf', 1024 + 1, 'application/pdf');
+
+ $response = $this->postJson(signedUploadUrl($this->workspace, $token), ['media' => $file]);
+
+ $response->assertStatus(422);
+ expect(Media::where('upload_token', $token)->exists())->toBeFalse();
+});
+
+test('stores a video upload via the streaming path', function () {
+ $token = (string) Str::uuid();
+ $file = UploadedFile::fake()->create('clip.mp4', 256, 'video/mp4');
+
+ $this->post(signedUploadUrl($this->workspace, $token), [
+ 'media' => $file,
+ ])->assertCreated();
+
+ $media = Media::where('upload_token', $token)->first();
+ expect($media)->not->toBeNull()
+ ->and($media->type->value)->toBe('video')
+ ->and(Storage::exists($media->path))->toBeTrue();
+});
+
test('rejects disallowed mime type', function () {
$token = (string) Str::uuid();
$file = UploadedFile::fake()->create('evil.exe', 10, 'application/octet-stream');
diff --git a/tests/Feature/Mcp/ListDiscordChannelsToolTest.php b/tests/Feature/Mcp/ListDiscordChannelsToolTest.php
new file mode 100644
index 000000000..c4c6d4241
--- /dev/null
+++ b/tests/Feature/Mcp/ListDiscordChannelsToolTest.php
@@ -0,0 +1,95 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Enums\SocialAccount\Platform;
+use App\Enums\UserWorkspace\Role;
+use App\Mcp\Servers\TryPostServer;
+use App\Mcp\Tools\SocialAccount\ListDiscordChannelsTool;
+use App\Models\SocialAccount;
+use App\Models\User;
+use App\Models\Workspace;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Http;
+use Illuminate\Testing\Fluent\AssertableJson;
+
+beforeEach(function () {
+ Cache::flush();
+ config([
+ 'trypost.platforms.discord.bot_token' => 'BOTTOKEN',
+ 'services.discord.client_id' => '999000111',
+ ]);
+
+ $this->user = User::factory()->create();
+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
+ $this->user->update(['current_workspace_id' => $this->workspace->id]);
+});
+
+test('lists discord channels as id and name', function () {
+ $account = SocialAccount::factory()->discord()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'platform_user_id' => '111222333',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.discord.api').'/guilds/111222333/channels' => Http::response([
+ ['id' => '1', 'name' => 'general', 'type' => 0],
+ ['id' => '2', 'name' => 'voice', 'type' => 2],
+ ], 200),
+ config('trypost.platforms.discord.api').'/guilds/111222333/roles' => Http::response([
+ ['id' => '111222333', 'name' => '@everyone', 'permissions' => '3072'],
+ ], 200),
+ config('trypost.platforms.discord.api').'/guilds/111222333/members/999000111' => Http::response(['roles' => []], 200),
+ ]);
+
+ $response = TryPostServer::actingAs($this->user)
+ ->tool(ListDiscordChannelsTool::class, ['account_id' => $account->id]);
+
+ $response->assertOk()
+ ->assertStructuredContent(function (AssertableJson $json) {
+ $json->has('channels', 1)
+ ->where('channels.0.id', '1')
+ ->where('channels.0.name', 'general');
+ });
+});
+
+test('returns an actionable error when discord is unavailable', function () {
+ $account = SocialAccount::factory()->discord()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'platform_user_id' => '111222333',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.discord.api').'/guilds/111222333/channels' => Http::response('upstream down', 500),
+ ]);
+
+ $response = TryPostServer::actingAs($this->user)
+ ->tool(ListDiscordChannelsTool::class, ['account_id' => $account->id]);
+
+ $response->assertHasErrors(['Discord channel lookup failed (500).']);
+});
+
+test('rejects non-discord accounts', function () {
+ $account = SocialAccount::factory()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'platform' => Platform::LinkedIn,
+ ]);
+
+ $response = TryPostServer::actingAs($this->user)
+ ->tool(ListDiscordChannelsTool::class, ['account_id' => $account->id]);
+
+ $response->assertHasErrors(['This tool only works with Discord social accounts.']);
+});
+
+test('cannot list channels for another workspace account', function () {
+ $otherWorkspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->discord()->create([
+ 'workspace_id' => $otherWorkspace->id,
+ ]);
+
+ $response = TryPostServer::actingAs($this->user)
+ ->tool(ListDiscordChannelsTool::class, ['account_id' => $account->id]);
+
+ $response->assertHasErrors(['Social account not found.']);
+});
diff --git a/tests/Feature/Mcp/ListPinterestBoardsToolTest.php b/tests/Feature/Mcp/ListPinterestBoardsToolTest.php
index 6dec26b57..1f0f48c39 100644
--- a/tests/Feature/Mcp/ListPinterestBoardsToolTest.php
+++ b/tests/Feature/Mcp/ListPinterestBoardsToolTest.php
@@ -47,6 +47,24 @@ test('lists pinterest boards as id and name', function () {
});
});
+test('returns an actionable error when pinterest token is expired', function () {
+ $account = SocialAccount::factory()->pinterest()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'access_token' => 'expired-token',
+ ]);
+
+ Http::fake([
+ config('trypost.platforms.pinterest.api').'/boards*' => Http::response([
+ 'message' => 'Access token has expired or been revoked',
+ ], 401),
+ ]);
+
+ $response = TryPostServer::actingAs($this->user)
+ ->tool(ListPinterestBoardsTool::class, ['account_id' => $account->id]);
+
+ $response->assertHasErrors(['Access token has expired or been revoked']);
+});
+
test('rejects non-pinterest accounts', function () {
$account = SocialAccount::factory()->create([
'workspace_id' => $this->workspace->id,
diff --git a/tests/Feature/Mcp/RequestMediaUploadToolTest.php b/tests/Feature/Mcp/RequestMediaUploadToolTest.php
index 51db448d6..e7177eb06 100644
--- a/tests/Feature/Mcp/RequestMediaUploadToolTest.php
+++ b/tests/Feature/Mcp/RequestMediaUploadToolTest.php
@@ -28,6 +28,9 @@ test('returns a single-use signed upload URL', function () {
->has('upload_url')
->has('expires_at')
->where('max_bytes', MediaType::Video->maxSizeInBytes())
+ ->where('max_bytes_by_type.image', MediaType::Image->maxSizeInBytes())
+ ->where('max_bytes_by_type.video', MediaType::Video->maxSizeInBytes())
+ ->where('max_bytes_by_type.document', MediaType::Document->maxSizeInBytes())
->where('field_name', 'media')
->etc();
});
diff --git a/tests/Feature/Services/Social/PinterestPublisherTest.php b/tests/Feature/Services/Social/PinterestPublisherTest.php
index c39e1ffd6..e2d62ef3a 100644
--- a/tests/Feature/Services/Social/PinterestPublisherTest.php
+++ b/tests/Feature/Services/Social/PinterestPublisherTest.php
@@ -518,6 +518,31 @@ test('pinterest publisher can get boards', function () {
expect($boards[0]['id'])->toBe('board_1');
});
+test('pinterest publisher paginates boards via bookmark', function () {
+ Http::fake([
+ config('trypost.platforms.pinterest.api').'/boards*' => Http::sequence()
+ ->push([
+ 'items' => [
+ ['id' => 'board_1', 'name' => 'Board 1'],
+ ],
+ 'bookmark' => 'page-2',
+ ], 200)
+ ->push([
+ 'items' => [
+ ['id' => 'board_2', 'name' => 'Board 2'],
+ ],
+ ], 200),
+ ]);
+
+ $boards = $this->publisher->getBoards($this->socialAccount);
+
+ expect($boards)->toHaveCount(2)
+ ->and($boards[0]['id'])->toBe('board_1')
+ ->and($boards[1]['id'])->toBe('board_2');
+
+ Http::assertSentCount(2);
+});
+
test('pinterest publisher can publish video pin', function () {
$this->postPlatform->update(['content_type' => ContentType::PinterestVideoPin]);