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
fix: review #5 — ContentSanitizer in all publishers, refresh lock, CheckSocialConnections includes TokenExpired
Paulo Castellanoa1df51234bf6
diff --git a/app/Console/Commands/CheckSocialConnections.php b/app/Console/Commands/CheckSocialConnections.phpindex f7df092e2..b8d35acdf 100644--- a/app/Console/Commands/CheckSocialConnections.php+++ b/app/Console/Commands/CheckSocialConnections.php@@ -19,7 +19,7 @@ class CheckSocialConnections extends Command{Workspace::query()->whereHas('socialAccounts', function ($query) {- $query->where('status', Status::Connected);+ $query->whereIn('status', [Status::Connected, Status::TokenExpired]);})->with('owner')->chunk(100, function ($workspaces) {diff --git a/app/Models/SocialAccount.php b/app/Models/SocialAccount.phpindex a8f9bdc0b..8e2a47f44 100644--- a/app/Models/SocialAccount.php+++ b/app/Models/SocialAccount.php@@ -136,7 +136,6 @@ class SocialAccount extends Model$this->update(['status' => Status::TokenExpired,'error_message' => $errorMessage,- 'disconnected_at' => now(),]);}diff --git a/app/Services/Social/ConnectionVerifier.php b/app/Services/Social/ConnectionVerifier.phpindex f2ec7bc48..50cbca7bf 100644--- a/app/Services/Social/ConnectionVerifier.php+++ b/app/Services/Social/ConnectionVerifier.php@@ -7,6 +7,7 @@ namespace App\Services\Social;use App\Enums\SocialAccount\Platform;use App\Exceptions\TokenExpiredException;use App\Models\SocialAccount;+use Illuminate\Support\Facades\Cache;use Illuminate\Support\Facades\Http;use Illuminate\Support\Facades\Log;@@ -46,19 +47,32 @@ class ConnectionVerifier*/private function refreshTokenIfNeeded(SocialAccount $account): void{- match ($account->platform) {- Platform::LinkedIn, Platform::LinkedInPage => $this->refreshLinkedInToken($account),- Platform::X => $this->refreshXToken($account),- Platform::Bluesky => $this->refreshBlueskyToken($account),- Platform::YouTube => $this->refreshYouTubeToken($account),- Platform::TikTok => $this->refreshTikTokToken($account),- Platform::Pinterest => $this->refreshPinterestToken($account),- Platform::Threads => $this->refreshThreadsToken($account),- Platform::Instagram => $this->refreshInstagramToken($account),- // Facebook uses page tokens that don't expire- // Mastodon tokens don't expire- default => null,- };+ $lock = Cache::lock("token_refresh:{$account->id}", 30);++ if (! $lock->get()) {+ // Another process is already refreshing this token+ $account->refresh();++ return;+ }++ try {+ match ($account->platform) {+ Platform::LinkedIn, Platform::LinkedInPage => $this->refreshLinkedInToken($account),+ Platform::X => $this->refreshXToken($account),+ Platform::Bluesky => $this->refreshBlueskyToken($account),+ Platform::YouTube => $this->refreshYouTubeToken($account),+ Platform::TikTok => $this->refreshTikTokToken($account),+ Platform::Pinterest => $this->refreshPinterestToken($account),+ Platform::Threads => $this->refreshThreadsToken($account),+ Platform::Instagram => $this->refreshInstagramToken($account),+ // Facebook uses page tokens that don't expire+ // Mastodon tokens don't expire+ default => null,+ };+ } finally {+ $lock->release();+ }}private function refreshLinkedInToken(SocialAccount $account): voiddiff --git a/app/Services/Social/MastodonPublisher.php b/app/Services/Social/MastodonPublisher.phpindex 4e37940aa..c6e076d63 100644--- a/app/Services/Social/MastodonPublisher.php+++ b/app/Services/Social/MastodonPublisher.php@@ -22,6 +22,8 @@ class MastodonPublisher{$this->validateContentLength($postPlatform);+ $content = $postPlatform->content ? app(ContentSanitizer::class)->sanitize($postPlatform->content, $postPlatform->platform) : null;+$account = $postPlatform->socialAccount;$instance = $account->meta['instance'] ?? 'https://mastodon.social';@@ -38,7 +40,7 @@ class MastodonPublisher// Create status$payload = [- 'status' => $postPlatform->content ?? '',+ 'status' => $content ?? '','visibility' => 'public',];diff --git a/app/Services/Social/PinterestPublisher.php b/app/Services/Social/PinterestPublisher.phpindex 480e52af1..cbce0587b 100644--- a/app/Services/Social/PinterestPublisher.php+++ b/app/Services/Social/PinterestPublisher.php@@ -32,15 +32,17 @@ class PinterestPublisher$account->refresh();}+ $content = $postPlatform->content ? app(ContentSanitizer::class)->sanitize($postPlatform->content, $postPlatform->platform) : null;+return match ($postPlatform->content_type) {- ContentType::PinterestPin => $this->publishImagePin($postPlatform),- ContentType::PinterestVideoPin => $this->publishVideoPin($postPlatform),- ContentType::PinterestCarousel => $this->publishCarousel($postPlatform),+ ContentType::PinterestPin => $this->publishImagePin($postPlatform, $content),+ ContentType::PinterestVideoPin => $this->publishVideoPin($postPlatform, $content),+ ContentType::PinterestCarousel => $this->publishCarousel($postPlatform, $content),default => throw new \Exception("Unsupported content type: {$postPlatform->content_type->value}"),};}- private function publishImagePin(PostPlatform $postPlatform): array+ private function publishImagePin(PostPlatform $postPlatform, ?string $content): array{$account = $postPlatform->socialAccount;$media = $postPlatform->media->first();@@ -87,8 +89,8 @@ class PinterestPublisher],];- if ($postPlatform->content) {- $payload['description'] = $postPlatform->content;+ if ($content) {+ $payload['description'] = $content;}if (! empty(data_get($postPlatform->meta, 'title'))) {@@ -122,7 +124,7 @@ class PinterestPublisher];}- private function publishVideoPin(PostPlatform $postPlatform): array+ private function publishVideoPin(PostPlatform $postPlatform, ?string $content): array{$account = $postPlatform->socialAccount;$media = $postPlatform->media->first();@@ -221,8 +223,8 @@ class PinterestPublisher],];- if ($postPlatform->content) {- $payload['description'] = $postPlatform->content;+ if ($content) {+ $payload['description'] = $content;}if (! empty(data_get($postPlatform->meta, 'title'))) {@@ -256,7 +258,7 @@ class PinterestPublisher];}- private function publishCarousel(PostPlatform $postPlatform): array+ private function publishCarousel(PostPlatform $postPlatform, ?string $content): array{$account = $postPlatform->socialAccount;$medias = $postPlatform->media;@@ -283,8 +285,8 @@ class PinterestPublisher],];- if ($postPlatform->content) {- $payload['description'] = $postPlatform->content;+ if ($content) {+ $payload['description'] = $content;}if (! empty(data_get($postPlatform->meta, 'title'))) {diff --git a/app/Services/Social/XPublisher.php b/app/Services/Social/XPublisher.phpindex d9b483b04..dbbdc8760 100644--- a/app/Services/Social/XPublisher.php+++ b/app/Services/Social/XPublisher.php@@ -28,6 +28,8 @@ class XPublisher{$this->validateContentLength($postPlatform);+ $content = $postPlatform->content ? app(ContentSanitizer::class)->sanitize($postPlatform->content, $postPlatform->platform) : null;+$account = $postPlatform->socialAccount;// Refresh token if expired or expiring soon@@ -40,8 +42,8 @@ class XPublisher$data = [];- if (! empty($postPlatform->content)) {- $data['text'] = $postPlatform->content;+ if (! empty($content)) {+ $data['text'] = $content;}$mediaIds = [];@@ -65,7 +67,7 @@ class XPublisher];}- if (empty($data['text'] ?? null) && empty($mediaIds)) {+ if (empty($content) && empty($mediaIds)) {throw new \Exception('X posts require either text or media. Please add content to your post.');}