fixes: image-url proxy + raw-publish fallback on rewrite failure
1. Clean image URLs
Article HTML was leaking the full Supabase Storage URL:
https://supabase.onsethost.com/storage/v1/object/public/distribute-media/<uuid>/<file>
Now rewritten on render to:
/img/distribute-media/<uuid>/<file>
Served by new /img/[...path] route handler that proxies to Supabase
with 24h public cache + 7d SWR. Better SEO (first-party images) and
stops leaking the storage host into article markup.
2. Stuck PR submissions
When the rewrite pipeline fails (Ollama 503 / bad model output), the
submission used to sit forever in ai_original_submissions without
becoming a public wp_imported_posts row. PR firms got "delivered"
status with no visible article anywhere.
/api/ai/submit now calls publishRawFallback() if rewriteSubmission
returns anything other than 'succeeded'. The fallback inserts a
wp_imported_posts row containing the raw HTML body with a visible
"Distributed as a press release — staff editorial rewrite pending"
banner at the top, so the article surfaces immediately. A future
retry job can swap in the rewritten content when Ollama recovers.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { ingestRawSubmission, rewriteSubmission } from "@/lib/ai/rewrite-pipeline";
|
||||
import { findViolations } from "@/lib/disallowed-phrases-guard";
|
||||
import { publishRawFallback } from "@/lib/ai/publish-raw-fallback";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 300;
|
||||
@@ -117,7 +118,24 @@ export async function POST(req: NextRequest) {
|
||||
const submissionId = await ingestRawSubmission(payload);
|
||||
const outcome = await rewriteSubmission({ submissionId, personaSlug: payload.personaSlug });
|
||||
|
||||
return NextResponse.json({ ok: true, submissionId, outcome });
|
||||
// If the rewrite failed (Ollama 503 / model output bad), publish the raw
|
||||
// press release with a "rewrite pending" notice so the submission is at
|
||||
// least visible. Without this, PR-firm submissions disappear when Ollama
|
||||
// is saturated.
|
||||
let fallback: { wp_id: number; wp_slug: string } | null = null;
|
||||
if (outcome.status !== "succeeded") {
|
||||
const meta: any = payload.metadata || {};
|
||||
fallback = await publishRawFallback({
|
||||
submissionId,
|
||||
rawTitle: payload.rawTitle,
|
||||
rawHtml: payload.rawHtml || null,
|
||||
rawContent: payload.rawContent,
|
||||
contributorName: payload.contributorName || null,
|
||||
featuredImageUrl: typeof meta.featured_image_url === "string" ? meta.featured_image_url : null,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ ok: true, submissionId, outcome, raw_fallback: fallback });
|
||||
} catch (err: any) {
|
||||
return NextResponse.json({ error: err.message || String(err) }, { status: 500 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user