Files
PAGIVA/src/lib/ai/post-queue-shared.ts
T
2026-11-27 09:28:29 +07:00

35 lines
1.4 KiB
TypeScript

export const POST_JOB_STATUS = {
QUEUED: "รอคิว",
RUNNING: "กำลังสร้าง",
COMPLETED: "พร้อมตรวจฉบับร่าง",
FAILED: "สร้างไม่สำเร็จ",
CANCELLED: "ยกเลิกแล้ว",
} as const;
export const POST_JOB_STAGE: Record<string, string> = {
queued: "รอเริ่มสร้างโพสต์",
research: "กำลังค้นและอ่านข่าว AI จากต่างประเทศ",
content: "Codex กำลังเขียนเนื้อหาและพรอมต์ภาพ",
image: "ChatGPT กำลังสร้างภาพ",
saving: "กำลังบันทึกฉบับร่าง",
};
export interface PostJobView {
id: string;
topic: string;
status: keyof typeof POST_JOB_STATUS;
stage: string;
postId: string | null;
error: string | null;
createdAt: string;
startedAt: string | null;
finishedAt: string | null;
}
/** Milestones, not an estimate of the image model's internal rendering progress. */
export function postJobProgress(job: Pick<PostJobView, "status" | "stage">): number {
if (job.status === "COMPLETED") return 100;
if (job.status === "QUEUED" || job.status === "CANCELLED") return 0;
return ({ research: 10, content: 25, image: 55, saving: 90 } as Record<string, number>)[job.stage] ?? 0;
}