fedi-feed-router/app/Modules/Lemmy/Services/LemmyPublisher.php
2025-07-05 18:26:04 +02:00

45 lines
1.2 KiB
PHP

<?php
namespace App\Modules\Lemmy\Services;
use App\Exceptions\PlatformAuthException;
use App\Models\Article;
use App\Models\PlatformAccount;
use App\Models\PlatformChannel;
use App\Services\Auth\LemmyAuthService;
use Exception;
class LemmyPublisher
{
private LemmyApiService $api;
private PlatformAccount $account;
public function __construct(PlatformAccount $account)
{
$this->api = new LemmyApiService($account->instance_url);
$this->account = $account;
}
/**
* @throws PlatformAuthException
* @throws Exception
*/
public function publishToChannel(Article $article, array $extractedData, PlatformChannel $channel): array
{
$token = LemmyAuthService::getToken($this->account);
// Use the language ID from extracted data (should be set during validation)
$languageId = $extractedData['language_id'] ?? null;
return $this->api->createPost(
$token,
$extractedData['title'] ?? 'Untitled',
$extractedData['description'] ?? '',
$channel->channel_id,
$article->url,
$extractedData['thumbnail'] ?? null,
$languageId
);
}
}