Fix publishing system
This commit is contained in:
parent
65fefb9534
commit
1b29c3fc13
7 changed files with 68 additions and 9 deletions
|
|
@ -237,6 +237,7 @@ public function createFeed(Request $request): JsonResponse
|
|||
|
||||
/**
|
||||
* Create channel for onboarding
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function createChannel(Request $request): JsonResponse
|
||||
{
|
||||
|
|
@ -253,6 +254,22 @@ public function createChannel(Request $request): JsonResponse
|
|||
|
||||
$validated = $validator->validated();
|
||||
|
||||
// Get the platform instance to check for active accounts
|
||||
$platformInstance = PlatformInstance::findOrFail($validated['platform_instance_id']);
|
||||
|
||||
// Check if there are active platform accounts for this instance
|
||||
$activeAccounts = PlatformAccount::where('instance_url', $platformInstance->url)
|
||||
->where('is_active', true)
|
||||
->get();
|
||||
|
||||
if ($activeAccounts->isEmpty()) {
|
||||
return $this->sendError(
|
||||
'Cannot create channel: No active platform accounts found for this instance. Please create a platform account first.',
|
||||
[],
|
||||
422
|
||||
);
|
||||
}
|
||||
|
||||
$channel = PlatformChannel::create([
|
||||
'platform_instance_id' => $validated['platform_instance_id'],
|
||||
'channel_id' => $validated['name'], // For Lemmy, this is the community name
|
||||
|
|
@ -263,14 +280,25 @@ public function createChannel(Request $request): JsonResponse
|
|||
'is_active' => true,
|
||||
]);
|
||||
|
||||
// Automatically attach the first active account to the channel
|
||||
$firstAccount = $activeAccounts->first();
|
||||
$channel->platformAccounts()->attach($firstAccount->id, [
|
||||
'is_active' => true,
|
||||
'priority' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->sendResponse(
|
||||
new PlatformChannelResource($channel->load(['platformInstance', 'language'])),
|
||||
'Channel created successfully.'
|
||||
new PlatformChannelResource($channel->load(['platformInstance', 'language', 'platformAccounts'])),
|
||||
'Channel created successfully and linked to platform account.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create route for onboarding
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function createRoute(Request $request): JsonResponse
|
||||
{
|
||||
|
|
@ -304,7 +332,7 @@ public function createRoute(Request $request): JsonResponse
|
|||
*/
|
||||
public function complete(): JsonResponse
|
||||
{
|
||||
// In a real implementation, you might want to update a user preference
|
||||
// In a real implementation, we might want to update a user preference
|
||||
// or create a setting that tracks onboarding completion
|
||||
// For now, we'll just return success since the onboarding status
|
||||
// is determined by the existence of platform accounts, feeds, and channels
|
||||
|
|
|
|||
|
|
@ -44,11 +44,36 @@ public function store(Request $request): JsonResponse
|
|||
|
||||
$validated['is_active'] = $validated['is_active'] ?? true;
|
||||
|
||||
// Get the platform instance to check for active accounts
|
||||
$platformInstance = \App\Models\PlatformInstance::findOrFail($validated['platform_instance_id']);
|
||||
|
||||
// Check if there are active platform accounts for this instance
|
||||
$activeAccounts = PlatformAccount::where('instance_url', $platformInstance->url)
|
||||
->where('is_active', true)
|
||||
->get();
|
||||
|
||||
if ($activeAccounts->isEmpty()) {
|
||||
return $this->sendError(
|
||||
'Cannot create channel: No active platform accounts found for this instance. Please create a platform account first.',
|
||||
[],
|
||||
422
|
||||
);
|
||||
}
|
||||
|
||||
$channel = PlatformChannel::create($validated);
|
||||
|
||||
// Automatically attach the first active account to the channel
|
||||
$firstAccount = $activeAccounts->first();
|
||||
$channel->platformAccounts()->attach($firstAccount->id, [
|
||||
'is_active' => true,
|
||||
'priority' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->sendResponse(
|
||||
new PlatformChannelResource($channel->load('platformInstance')),
|
||||
'Platform channel created successfully!',
|
||||
new PlatformChannelResource($channel->load(['platformInstance', 'platformAccounts'])),
|
||||
'Platform channel created successfully and linked to platform account!',
|
||||
201
|
||||
);
|
||||
} catch (ValidationException $e) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class PublishToLemmyJob implements ShouldQueue
|
|||
public function __construct(
|
||||
private readonly Article $article
|
||||
) {
|
||||
$this->onQueue('lemmy-posts');
|
||||
$this->onQueue('publishing');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
class PublishArticle implements ShouldQueue
|
||||
{
|
||||
public string|null $queue = 'lemmy-publish';
|
||||
public string|null $queue = 'publishing';
|
||||
public int $delay = 300;
|
||||
public int $tries = 3;
|
||||
public int $backoff = 300;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
/**
|
||||
* @method static findMany(mixed $channel_ids)
|
||||
* @method static create(array $array)
|
||||
* @property integer $id
|
||||
* @property integer $platform_instance_id
|
||||
* @property PlatformInstance $platformInstance
|
||||
|
|
|
|||
|
|
@ -33,11 +33,16 @@ public function publishToChannel(Article $article, array $extractedData, Platfor
|
|||
// Use the language ID from extracted data (should be set during validation)
|
||||
$languageId = $extractedData['language_id'] ?? null;
|
||||
|
||||
// Resolve community name to numeric ID if needed
|
||||
$communityId = is_numeric($channel->channel_id)
|
||||
? (int) $channel->channel_id
|
||||
: $this->api->getCommunityId($channel->channel_id, $token);
|
||||
|
||||
return $this->api->createPost(
|
||||
$token,
|
||||
$extractedData['title'] ?? 'Untitled',
|
||||
$extractedData['description'] ?? '',
|
||||
(int) $channel->channel_id,
|
||||
$communityId,
|
||||
$article->url,
|
||||
$extractedData['thumbnail'] ?? null,
|
||||
$languageId
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@
|
|||
'defaults' => [
|
||||
'supervisor-1' => [
|
||||
'connection' => 'redis',
|
||||
'queue' => ['default', 'lemmy-posts', 'lemmy-publish', 'feed-discovery'],
|
||||
'queue' => ['default', 'publishing', 'feed-discovery'],
|
||||
'balance' => 'auto',
|
||||
'autoScalingStrategy' => 'time',
|
||||
'maxProcesses' => 1,
|
||||
|
|
|
|||
Loading…
Reference in a new issue