新增发布校准接口
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { requireApiAccess } from "../../../../../../lib/api/auth";
|
||||
import {
|
||||
GEO_RUBRIC_V1,
|
||||
scoreOptimizedArticle,
|
||||
} from "../../../../../../lib/calibration/scoring";
|
||||
import { getRepositoryFromRuntime } from "../../../../../../lib/db/repository";
|
||||
|
||||
interface RouteContext {
|
||||
params: Promise<{ jobId: string }>;
|
||||
}
|
||||
|
||||
export async function POST(request: Request, context: RouteContext) {
|
||||
const access = requireApiAccess(request);
|
||||
if (!access.ok) {
|
||||
return access.response;
|
||||
}
|
||||
|
||||
const { jobId } = await context.params;
|
||||
const repository = getRepositoryFromRuntime();
|
||||
const article = await repository.getLatestOptimizedArticle(jobId);
|
||||
const qaReport = await repository.getLatestQaReport(jobId);
|
||||
if (!article || !qaReport) {
|
||||
return NextResponse.json(
|
||||
{ error: "Optimize the article before scoring calibration" },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
|
||||
await repository.saveRubricVersion(GEO_RUBRIC_V1);
|
||||
const scoringRun = await repository.saveScoringRun(
|
||||
scoreOptimizedArticle({ jobId, article, qaReport }),
|
||||
);
|
||||
|
||||
return NextResponse.json({ scoringRun }, { status: 201 });
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { requireApiAccess } from "../../../../../lib/api/auth";
|
||||
import { publicationInputSchema } from "../../../../../lib/calibration/validation";
|
||||
import { getRepositoryFromRuntime } from "../../../../../lib/db/repository";
|
||||
|
||||
interface RouteContext {
|
||||
params: Promise<{ jobId: string }>;
|
||||
}
|
||||
|
||||
export async function GET(request: Request, context: RouteContext) {
|
||||
const access = requireApiAccess(request);
|
||||
if (!access.ok) {
|
||||
return access.response;
|
||||
}
|
||||
|
||||
const { jobId } = await context.params;
|
||||
const repository = getRepositoryFromRuntime();
|
||||
return NextResponse.json({
|
||||
publications: await repository.listPublicationRecords(jobId),
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request, context: RouteContext) {
|
||||
const access = requireApiAccess(request);
|
||||
if (!access.ok) {
|
||||
return access.response;
|
||||
}
|
||||
|
||||
const { jobId } = await context.params;
|
||||
const repository = getRepositoryFromRuntime();
|
||||
const article = await repository.getLatestOptimizedArticle(jobId);
|
||||
if (!article?.revision) {
|
||||
return NextResponse.json(
|
||||
{ error: "Optimize the article before registering publication" },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const input = publicationInputSchema.parse(await request.json());
|
||||
const publication = await repository.createPublicationRecord({
|
||||
job_id: jobId,
|
||||
revision: article.revision,
|
||||
platform: input.platform,
|
||||
url: input.url,
|
||||
published_at: input.published_at,
|
||||
status: "published",
|
||||
notes: input.notes,
|
||||
});
|
||||
|
||||
return NextResponse.json({ publication }, { status: 201 });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Invalid publication";
|
||||
return NextResponse.json({ error: message }, { status: 400 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user