trypost/app/Enums/SocialAccount/Platform.php
Paulo Castellano dafdd5da43 feat: media gallery picker, custom emoji picker, preview tabs, real platform logos
- gallery: extract /assets tabs (uploads, Unsplash, Giphy) into shared
  GalleryBrowser used by both /assets and a new MediaPickerDialog inside the
  post editor; add JSON search endpoint for workspace assets with tests
- emoji: replace broken emoji-picker-element web component with a custom
  EmojiPicker (full Unicode set, search, categories, recently-used,
  light/dark, i18n)
- preview tab: platform selector pills, variant tabs (data-driven from
  content_types map) so the user can switch Feed/Reel/Story etc. and have
  it autosave through the same handler ScheduleTab uses
- platform logos: shared usePlatformLogo composable (logo + label + content
  types); replaces inline maps across 5 components, fixes
  instagram-facebook falling back to default.png
- tooltips: hover details (display_name · @username + platform label) on
  platform avatars across editor, posts list and calendar
- settings cards: show ` · @username` in the title bar so multiple accounts
  on the same network are distinguishable
- routes: drop the throttle:6,1 group middleware on social connect routes
  (was 429ing legitimate OAuth retries) and rely on the default limiter
2026-05-01 14:53:49 -03:00

211 lines
6.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Enums\SocialAccount;
use App\Enums\Media\Type as MediaType;
enum Platform: string
{
case LinkedIn = 'linkedin';
case LinkedInPage = 'linkedin-page';
case X = 'x';
case TikTok = 'tiktok';
case YouTube = 'youtube';
case Facebook = 'facebook';
case Instagram = 'instagram';
case InstagramFacebook = 'instagram-facebook';
case Threads = 'threads';
case Pinterest = 'pinterest';
case Bluesky = 'bluesky';
case Mastodon = 'mastodon';
public function label(): string
{
return match ($this) {
self::LinkedIn => 'LinkedIn',
self::LinkedInPage => 'LinkedIn Page',
self::X => 'X',
self::TikTok => 'TikTok',
self::YouTube => 'YouTube Shorts',
self::Facebook => 'Facebook Page',
self::Instagram => 'Instagram (Standalone)',
self::InstagramFacebook => 'Instagram (Facebook Business)',
self::Threads => 'Threads',
self::Pinterest => 'Pinterest',
self::Bluesky => 'Bluesky',
self::Mastodon => 'Mastodon',
};
}
public function color(): string
{
return match ($this) {
self::LinkedIn, self::LinkedInPage => '#0A66C2',
self::X => '#000000',
self::TikTok => '#000000',
self::YouTube => '#FF0000',
self::Facebook => '#1877F2',
self::Instagram => '#E4405F',
self::InstagramFacebook => '#E4405F',
self::Threads => '#000000',
self::Pinterest => '#E60023',
self::Bluesky => '#0085FF',
self::Mastodon => '#6364FF',
};
}
public function allowedMediaTypes(): array
{
return match ($this) {
self::LinkedIn, self::LinkedInPage => [MediaType::Image, MediaType::Video, MediaType::Document],
self::X => [MediaType::Image, MediaType::Video],
self::TikTok => [MediaType::Video],
self::YouTube => [MediaType::Video],
self::Facebook => [MediaType::Image, MediaType::Video],
self::Instagram, self::InstagramFacebook => [MediaType::Image, MediaType::Video],
self::Threads => [MediaType::Image, MediaType::Video],
self::Pinterest => [MediaType::Image, MediaType::Video],
self::Bluesky => [MediaType::Image, MediaType::Video],
self::Mastodon => [MediaType::Image, MediaType::Video],
};
}
public function maxImages(): int
{
return match ($this) {
self::LinkedIn, self::LinkedInPage => 1,
self::X => 4,
self::TikTok => 0,
self::YouTube => 0,
self::Facebook => 10,
self::Instagram, self::InstagramFacebook => 10,
self::Threads => 10,
self::Pinterest => 5,
self::Bluesky => 4,
self::Mastodon => 4,
};
}
public function maxContentLength(): int
{
return match ($this) {
self::LinkedIn, self::LinkedInPage => 3000,
self::X => 280,
self::TikTok => 2200,
self::YouTube => 5000,
self::Facebook => 63206,
self::Instagram, self::InstagramFacebook => 2200,
self::Threads => 500,
self::Pinterest => 800,
self::Bluesky => 300,
self::Mastodon => 500,
};
}
/**
* @return array<string>
*/
public function requiredPublishScopes(): array
{
return match ($this) {
self::Instagram => ['instagram_business_content_publish'],
self::InstagramFacebook => ['instagram_content_publish'],
self::Facebook => ['pages_manage_posts'],
self::TikTok => ['video.publish'],
self::YouTube => ['https://www.googleapis.com/auth/youtube.upload'],
self::LinkedIn => ['w_member_social'],
self::LinkedInPage => ['w_organization_social'],
self::X => ['tweet.write'],
self::Threads => ['threads_content_publish'],
self::Pinterest => ['pins:write'],
self::Bluesky => [],
self::Mastodon => ['write:statuses'],
};
}
public function supportsTextOnly(): bool
{
return match ($this) {
self::LinkedIn, self::LinkedInPage => true,
self::X => true,
self::TikTok => false,
self::YouTube => false,
self::Facebook => true,
self::Instagram, self::InstagramFacebook => false,
self::Threads => true,
self::Pinterest => false,
self::Bluesky => true,
self::Mastodon => true,
};
}
public function requiresContent(): bool
{
return match ($this) {
self::YouTube => true,
default => false,
};
}
public function queue(): string
{
return 'social-'.$this->value;
}
/**
* @return array<string>
*/
public static function allQueues(): array
{
return array_map(fn (self $platform) => $platform->queue(), self::cases());
}
public function instagramGraphBaseUrl(): string
{
return match ($this) {
self::InstagramFacebook => 'https://graph.facebook.com/v25.0',
self::Instagram => 'https://graph.instagram.com/v25.0',
default => 'https://graph.instagram.com/v25.0',
};
}
public function isEnabled(): bool
{
return config("trypost.platforms.{$this->value}.enabled", true);
}
/**
* Static, platform-specific data exposed to the frontend (e.g. TikTok privacy options,
* compliance URLs). Returns an empty array for platforms with no extra config.
*
* @return array<string, mixed>
*/
public function publishConfig(): array
{
return match ($this) {
self::TikTok => [
'privacyLevelOptions' => [
'PUBLIC_TO_EVERYONE',
'MUTUAL_FOLLOW_FRIENDS',
'FOLLOWER_OF_CREATOR',
'SELF_ONLY',
],
'musicUsageConfirmationUrl' => 'https://www.tiktok.com/legal/page/global/music-usage-confirmation/en',
'brandedContentPolicyUrl' => 'https://www.tiktok.com/legal/page/global/bc-policy/en',
],
default => [],
};
}
/**
* Get all enabled platforms.
*
* @return array<self>
*/
public static function enabled(): array
{
return array_filter(self::cases(), fn (self $platform) => $platform->isEnabled());
}
}