Add a Publisher abstraction and queued job to publish from the UI
Introduce Publisher/PublisherManager (WordPress + Reddit implementations) so publishing logic is shared between the CLI, the queue, and future network integrations. Add a "Publish" button on the Posts page that dispatches PublishPostJob instead of blocking the request — Reddit's publisher shells out to the existing Playwright sidecar and can take tens of seconds, so it can't run synchronously in a web request. Adds a `target` field (e.g. subreddit) and `publishing` status to Post, plus a `publish_error` field so failures surface in the UI. Refactors posts:publish to delegate to WordPressPublisher without changing its CLI output contract (existing tests pass unchanged). Also fixes two bugs found along the way: UpdatePostRequest was silently dropping `published_url` from PATCH requests (never in its validation rules, despite AI_API.md documenting it), and three Livewire index-page tests were broken by the earlier auth change (never re-run after adding the `auth` middleware) since they hit routes via HTTP without a logged-in user. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,7 @@ class Login extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
request()->session()->regenerate();
|
||||
session()->regenerate();
|
||||
|
||||
$this->redirect(route('sites.index'), navigate: true);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Jobs\PublishPostJob;
|
||||
use App\Models\Post;
|
||||
use App\Models\Site;
|
||||
use App\Models\SocialAccount;
|
||||
use App\Support\Publishing\PublisherManager;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
|
||||
@@ -25,21 +27,45 @@ class Index extends Component
|
||||
|
||||
public string $body = '';
|
||||
|
||||
public string $target = '';
|
||||
|
||||
public string $status = 'draft';
|
||||
|
||||
public string $scheduledAt = '';
|
||||
|
||||
public ?string $publishNotice = null;
|
||||
|
||||
public function render()
|
||||
{
|
||||
$posts = Post::with(['site', 'socialAccount'])->orderByDesc('created_at')->get();
|
||||
|
||||
return view('livewire.posts.index', [
|
||||
'posts' => Post::with(['site', 'socialAccount'])->orderByDesc('created_at')->get(),
|
||||
'posts' => $posts,
|
||||
'sites' => Site::orderBy('name')->get(),
|
||||
'accounts' => SocialAccount::orderBy('username')->get(),
|
||||
'types' => Post::TYPES,
|
||||
'statuses' => Post::STATUSES,
|
||||
'hasPublishing' => $posts->contains('status', 'publishing'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function publish(int $id): void
|
||||
{
|
||||
$this->publishNotice = null;
|
||||
|
||||
$post = Post::with('site')->findOrFail($id);
|
||||
|
||||
if (! app(PublisherManager::class)->resolve($post)) {
|
||||
$this->publishNotice = "No publisher available yet for post type '{$post->type}'.";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$post->update(['status' => 'publishing', 'publish_error' => null]);
|
||||
|
||||
PublishPostJob::dispatch($post->id);
|
||||
}
|
||||
|
||||
public function create(): void
|
||||
{
|
||||
$this->resetForm();
|
||||
@@ -55,6 +81,7 @@ class Index extends Component
|
||||
$this->type = $post->type;
|
||||
$this->title = (string) $post->title;
|
||||
$this->body = $post->body;
|
||||
$this->target = (string) $post->target;
|
||||
$this->status = $post->status;
|
||||
$this->scheduledAt = $post->scheduled_at?->format('Y-m-d\TH:i') ?? '';
|
||||
$this->showForm = true;
|
||||
@@ -68,6 +95,7 @@ class Index extends Component
|
||||
'type' => ['required', 'string', 'in:' . implode(',', Post::TYPES)],
|
||||
'title' => ['nullable', 'string', 'max:255'],
|
||||
'body' => ['required', 'string'],
|
||||
'target' => ['nullable', 'string', 'max:255'],
|
||||
'status' => ['required', 'string', 'in:' . implode(',', Post::STATUSES)],
|
||||
'scheduledAt' => ['nullable', 'date'],
|
||||
]);
|
||||
@@ -78,6 +106,7 @@ class Index extends Component
|
||||
'type' => $validated['type'],
|
||||
'title' => $validated['title'] ?: null,
|
||||
'body' => $validated['body'],
|
||||
'target' => $validated['target'] ?: null,
|
||||
'status' => $validated['status'],
|
||||
'scheduled_at' => $validated['scheduledAt'] ?: null,
|
||||
]);
|
||||
@@ -99,6 +128,7 @@ class Index extends Component
|
||||
$this->type = '';
|
||||
$this->title = '';
|
||||
$this->body = '';
|
||||
$this->target = '';
|
||||
$this->status = 'draft';
|
||||
$this->scheduledAt = '';
|
||||
$this->resetValidation();
|
||||
|
||||
Reference in New Issue
Block a user