wip: article AI polish, category SEO fields, cover generator, membership plan seeder
This commit is contained in:
@@ -4,41 +4,48 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\Ai\Jobs;
|
||||
|
||||
use App\Domain\Media\ArticleCoverService;
|
||||
use App\Models\Article;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Phase-2 stub: auto-pick or generate a cover image for an article.
|
||||
* Dispatch later from import scripts / artisan batch; process via Workerman/queue.
|
||||
* Auto-pick a cover from article body embeds / attachments.
|
||||
* `generate` strategy is reserved for future text-to-image.
|
||||
*/
|
||||
class GenerateArticleCoverJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public int $articleId,
|
||||
public string $strategy = 'auto', // auto|from_content|generate
|
||||
public string $strategy = 'auto', // auto|from_content|attachment|generate
|
||||
) {
|
||||
$this->onQueue('ai-content');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
public function handle(ArticleCoverService $covers): void
|
||||
{
|
||||
$article = Article::query()->find($this->articleId);
|
||||
|
||||
if ($article === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Intentionally unimplemented in phase 1.
|
||||
Log::info('GenerateArticleCoverJob stub skipped', [
|
||||
'article_id' => $article->id,
|
||||
'strategy' => $this->strategy,
|
||||
'cover_status' => $article->cover_status,
|
||||
]);
|
||||
try {
|
||||
$covers->apply($article, $this->strategy);
|
||||
} catch (\Throwable $exception) {
|
||||
Log::warning('GenerateArticleCoverJob failed.', [
|
||||
'article_id' => $this->articleId,
|
||||
'strategy' => $this->strategy,
|
||||
'message' => $exception->getMessage(),
|
||||
]);
|
||||
|
||||
$article->forceFill([
|
||||
'cover_status' => ArticleCoverService::STATUS_FAILED,
|
||||
'cover_generated_at' => now(),
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,15 +34,27 @@ class OptimizeArticleContentJob implements ShouldQueue
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $llm->complete($article->content, [
|
||||
$result = $llm->complete((string) $article->content, [
|
||||
'title' => $article->title,
|
||||
'article_id' => $article->id,
|
||||
'content_format' => $article->content_format,
|
||||
]);
|
||||
|
||||
$article->forceFill([
|
||||
'ai_summary' => $result['summary'] ?? null,
|
||||
'ai_suggestions' => $result['suggestions'] ?? [],
|
||||
])->save();
|
||||
$updates = [
|
||||
'ai_summary' => filled($result['summary'] ?? null) ? (string) $result['summary'] : $article->ai_summary,
|
||||
'ai_suggestions' => array_values($result['suggestions'] ?? []),
|
||||
];
|
||||
|
||||
if (filled($result['polished_content'] ?? null)) {
|
||||
$updates['ai_polished_content'] = (string) $result['polished_content'];
|
||||
}
|
||||
|
||||
// Fill empty SEO description from the model when the author left it blank.
|
||||
if (blank($article->description) && filled($result['description'] ?? null)) {
|
||||
$updates['description'] = (string) $result['description'];
|
||||
}
|
||||
|
||||
$article->forceFill($updates)->save();
|
||||
} catch (\Throwable $exception) {
|
||||
Log::warning('Article content optimization failed.', [
|
||||
'article_id' => $this->articleId,
|
||||
|
||||
Reference in New Issue
Block a user