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.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
Say why media is refused on every network, not only on four (#522)
Paulo Castellano10b7f3bd7cef
diff --git a/resources/js/components/posts/composer/PostComposerDialog.vue b/resources/js/components/posts/composer/PostComposerDialog.vueindex 35d2346ef..2cb9bee27 100644--- a/resources/js/components/posts/composer/PostComposerDialog.vue+++ b/resources/js/components/posts/composer/PostComposerDialog.vue@@ -1630,8 +1630,8 @@ const metaRequirement = (account: ComposerAccount): string | null => {return result.valid ? null : result.tooltipKey;};-/** Media rules about the set as a whole; a single item's issue shows on that item. */-const SET_MEDIA_WARNINGS = new Set([+/** Media warnings about the post's set as a whole, shown above the card's editor. */+const SET_MEDIA_WARNINGS = ['requires_media','no_mixed_media','max_files_exceeded',@@ -1640,7 +1640,9 @@ const SET_MEDIA_WARNINGS = new Set(['no_image_allowed','no_document_allowed','document_not_alone',-]);+];+/** Every media warning the card already shows above its editor, so its media warnings skip them. */+const MEDIA_WARNINGS_ABOVE_EDITOR = [...SET_MEDIA_WARNINGS, 'text_only'];const setMediaWarning = (account: ComposerAccount | undefined,): MediaValidationWarning | null => {@@ -1651,7 +1653,15 @@ const setMediaWarning = (destination.media,);- return warning && SET_MEDIA_WARNINGS.has(warning.key) ? warning : null;+ if (!filled(warning)) {+ return null;+ }++ if (!SET_MEDIA_WARNINGS.includes(warning.key)) {+ return null;+ }++ return warning;};const hasBlockingIssues = computed(() => blockingIssue.value !== null);const isBatch = computed(@@ -2912,6 +2922,7 @@ const onDialogOpenChange = (value: boolean): void => {groupDestination(group).content_type":media="groupDestination(group).media"+ :shown-elsewhere="MEDIA_WARNINGS_ABOVE_EDITOR":media-editing="true":disabled="cropUploading"@edit:media="diff --git a/resources/js/components/posts/editor/ChannelMediaWarnings.vue b/resources/js/components/posts/editor/ChannelMediaWarnings.vueindex ad6c7a4e7..0d059e604 100644--- a/resources/js/components/posts/editor/ChannelMediaWarnings.vue+++ b/resources/js/components/posts/editor/ChannelMediaWarnings.vue@@ -4,17 +4,11 @@ import { computed } from 'vue';import MediaRulesWarning from '@/components/posts/editor/MediaRulesWarning.vue';import { getMediaValidationWarning } from '@/composables/useMedia';+import { filled } from '@/lib/helpers';import { getInstagramImageAspectIssues } from '@/lib/instagramImageAspect';import type { MediaItem } from '@/types/media';import { Platform } from '@/types/platform';-const RULES_WARNING_PLATFORMS: string[] = [- Platform.Instagram,- Platform.InstagramFacebook,- Platform.Facebook,- Platform.Pinterest,-];-const ASPECT_KEYS = ['aspect_ratio_too_narrow', 'aspect_ratio_too_wide'];const props = withDefaults(@@ -24,8 +18,10 @@ const props = withDefaults(media: MediaItem[];disabled?: boolean;mediaEditing?: boolean;+ /** Warning keys the parent already shows, so they are not shown twice. */+ shownElsewhere?: string[];}>(),- { disabled: false, mediaEditing: false },+ { disabled: false, mediaEditing: false, shownElsewhere: () => [] },);const emit = defineEmits<{ 'edit:media': [index: number] }>();@@ -42,15 +38,15 @@ const aspectIssues = computed(() =>: [],);-const hiddenKeys = computed(() =>- aspectIssues.value.length ? ASPECT_KEYS : [],-);--const hasRulesWarning = computed(() => {- if (!RULES_WARNING_PLATFORMS.includes(props.platform)) {- return false;+const hiddenKeys = computed((): string[] => {+ if (filled(aspectIssues.value)) {+ return [...ASPECT_KEYS, ...props.shownElsewhere];}+ return props.shownElsewhere;+});++const hasRulesWarning = computed(() => {const warning = getMediaValidationWarning(props.contentType, props.media);return (diff --git a/tests/Browser/ChannelMediaIssueTest.php b/tests/Browser/ChannelMediaIssueTest.phpindex 488da47b7..9da127755 100644--- a/tests/Browser/ChannelMediaIssueTest.php+++ b/tests/Browser/ChannelMediaIssueTest.php@@ -11,6 +11,7 @@ use App\Models\SocialAccount;use App\Models\User;use App\Models\Workspace;use Illuminate\Support\Facades\Storage;+use Illuminate\Support\Str;test('an Instagram media warning links to the network limits', function () {[$post] = seedInstagramFeedImagePost(size: 9 * 1024 * 1024);@@ -264,3 +265,130 @@ test('an Instagram feed post without media shows the inline warning once, under->assertDisabled('@composer-submit')->assertNoJavaScriptErrors();});++/**+ * @param array<string, mixed> $overrides+ * @return array<string, mixed>+ */+function channelMediaIssueItem(string $id, array $overrides = []): array+{+ return [+ 'id' => $id,+ 'type' => 'image',+ 'mime_type' => 'image/jpeg',+ 'path' => "uploads/{$id}.jpg",+ 'url' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',+ 'size' => 1024,+ 'meta' => ['width' => 1080, 'height' => 1080],+ ...$overrides,+ ];+}++/**+ * @param array<string, mixed> $attributes+ */+function seedChannelMediaIssuePost(Platform $platform, ContentType $type, array $attributes): Post+{+ $user = User::factory()->create();+ $workspace = Workspace::factory()->create(['user_id' => $user->id]);+ $workspace->members()->attach($user->id, membershipPivot('member'));+ $user->update(['current_workspace_id' => $workspace->id]);++ $account = SocialAccount::factory()->create(['workspace_id' => $workspace->id, 'platform' => $platform]);+ $post = Post::factory()->forAccount($account, $type)->create(['user_id' => $user->id, ...$attributes]);+ test()->actingAs($user);++ return $post;+}++test('a thread reply says why its media is refused', function (Platform $platform, ContentType $type) {+ $post = seedChannelMediaIssuePost($platform, $type, [+ 'content' => 'The thread starts here',+ 'media' => [],+ 'meta' => ['thread_replies' => [[+ 'text' => 'Five photos in one reply',+ 'media' => array_map(fn (int $index): array => channelMediaIssueItem("reply-photo-{$index}"), range(1, 5)),+ ]]],+ ]);++ $page = visit(route('app.posts.edit', $post));+ waitFor($page, '@media-rules-warning');++ $page->assertSeeIn('@media-rules-warning', __('posts.form.warnings.max_files_exceeded', ['max' => '4', 'current' => '5']))+ ->assertDisabled('@composer-submit')+ ->assertNoJavaScriptErrors();+})->with([+ 'X' => [Platform::X, ContentType::XPost],+ 'Bluesky' => [Platform::Bluesky, ContentType::BlueskyPost],+ 'Mastodon' => [Platform::Mastodon, ContentType::MastodonPost],+]);++test('a warning about the post\'s media as a whole shows once, above the editor', function () {+ $post = seedChannelMediaIssuePost(Platform::LinkedIn, ContentType::LinkedInPost, [+ 'content' => 'A photo next to a video',+ 'media' => [+ channelMediaIssueItem('photo-1'),+ channelMediaIssueItem('video-1', ['type' => 'video', 'mime_type' => 'video/mp4', 'path' => 'uploads/video-1.mp4', 'meta' => ['duration' => 10]]),+ ],+ ]);++ $page = visit(route('app.posts.edit', $post));+ $warning = "composer-media-warning-{$post->social_account_id}";+ waitFor($page, "@{$warning}");++ $page->assertSeeIn("@{$warning}", __('posts.form.warnings.no_mixed_media'))+ ->assertMissing('@media-rules-warning')+ ->assertNoJavaScriptErrors();+});++test('every network says why its media is refused inside its card', function (Platform $platform, ContentType $type, array $item, string $warning, string $docsAnchor) {+ $post = seedChannelMediaIssuePost($platform, $type, ['content' => 'A file this network refuses', 'media' => [$item]]);++ $page = visit(route('app.posts.edit', $post));+ waitFor($page, '@media-rules-warning');++ expect((string) $page->script('document.querySelector("[data-testid=media-rules-warning] span")?.firstChild?.textContent'))+ ->toContain(Str::before(__("posts.form.warnings.{$warning}"), ':'))+ ->and($page->script('document.querySelector("[data-testid=media-rules-warning] a")?.href'))+ ->toBe("https://docs.trypost.it/knowledge-base/media#{$docsAnchor}");+ $page->assertDisabled('@composer-submit')+ ->assertNoJavaScriptErrors();+})->with(function (): array {+ $tooLargeImage = channelMediaIssueItem('photo-1', ['size' => 60 * 1024 * 1024]);+ $tooLargeVideo = channelMediaIssueItem('video-1', ['type' => 'video', 'mime_type' => 'video/mp4', 'path' => 'uploads/video-1.mp4', 'size' => 2 * 1024 * 1024 * 1024, 'meta' => ['duration' => 10]]);+ $gif = channelMediaIssueItem('gif-1', ['mime_type' => 'image/gif', 'path' => 'uploads/gif-1.gif']);++ return [+ 'Facebook' => [Platform::Facebook, ContentType::FacebookPost, $tooLargeImage, 'image_too_large', 'facebook'],+ 'Instagram' => [Platform::Instagram, ContentType::InstagramFeed, $tooLargeImage, 'image_too_large', 'instagram'],+ 'Instagram via Facebook' => [Platform::InstagramFacebook, ContentType::InstagramFeed, $tooLargeImage, 'image_too_large', 'instagram'],+ 'Threads' => [Platform::Threads, ContentType::ThreadsPost, $gif, 'gif_not_allowed', 'threads'],+ 'X' => [Platform::X, ContentType::XPost, $tooLargeImage, 'image_too_large', 'x-twitter'],+ 'LinkedIn' => [Platform::LinkedIn, ContentType::LinkedInPost, $tooLargeImage, 'image_too_large', 'linkedin'],+ 'LinkedIn Page' => [Platform::LinkedInPage, ContentType::LinkedInPagePost, $tooLargeImage, 'image_too_large', 'linkedin'],+ 'TikTok' => [Platform::TikTok, ContentType::TikTokVideo, $tooLargeVideo, 'video_too_large', 'tiktok'],+ 'YouTube' => [Platform::YouTube, ContentType::YouTubeShort, $tooLargeVideo, 'video_too_large', 'youtube'],+ 'Pinterest' => [Platform::Pinterest, ContentType::PinterestPin, $tooLargeImage, 'image_too_large', 'pinterest'],+ 'Bluesky' => [Platform::Bluesky, ContentType::BlueskyPost, $tooLargeVideo, 'video_too_large', 'bluesky'],+ 'Mastodon' => [Platform::Mastodon, ContentType::MastodonPost, $tooLargeImage, 'image_too_large', 'mastodon'],+ 'Telegram' => [Platform::Telegram, ContentType::TelegramPost, $tooLargeImage, 'image_too_large', 'telegram'],+ 'Discord' => [Platform::Discord, ContentType::DiscordMessage, $tooLargeImage, 'image_too_large', 'discord'],+ 'Google Business' => [Platform::GoogleBusiness, ContentType::GoogleBusinessPost, $gif, 'gif_not_allowed', 'google-business-profile'],+ ];+});++test('a post type that takes no media says so once, above the editor', function () {+ $post = seedChannelMediaIssuePost(Platform::X, ContentType::XPoll, [+ 'content' => 'Which one?',+ 'meta' => ['poll' => ['options' => ['Yes', 'No'], 'duration_minutes' => 1440]],+ 'media' => [channelMediaIssueItem('photo-1')],+ ]);++ $page = visit(route('app.posts.edit', $post));+ $warning = "composer-text-only-warning-{$post->social_account_id}";+ waitFor($page, "@{$warning}");++ $page->assertSeeIn("@{$warning}", __('posts.form.warnings.text_only'))+ ->assertMissing('@media-rules-warning')+ ->assertNoJavaScriptErrors();+});