47 lines
1.3 KiB
PHP
47 lines
1.3 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;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $extractedData
|
|
* @return array<string, mixed>
|
|
* @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
|
|
);
|
|
}
|
|
|
|
}
|