diff --git a/scripts/ai-automation-worker.mjs b/scripts/ai-automation-worker.mjs index 9f998b4..b78ad1e 100644 --- a/scripts/ai-automation-worker.mjs +++ b/scripts/ai-automation-worker.mjs @@ -88,9 +88,18 @@ async function image(body, dir) { await generatedImage.click(); const downloadButton = page.getByRole("button", { name: /^(download|ดาวน์โหลด)$/i }).last(); await downloadButton.waitFor({ state: "visible", timeout: 20_000 }); - const downloadEvent = page.waitForEvent("download", { timeout: 20_000 }); - await downloadButton.click(); - const download = await downloadEvent; + const [download] = await Promise.all([ + page.waitForEvent("download", { timeout: 60_000 }), + (async () => { + await downloadButton.click(); + const menuItem = page.getByRole("menuitem", { name: /^(download image|ดาวน์โหลดรูปภาพ)$/i }).first(); + if (await menuItem.waitFor({ state: "visible", timeout: 1_000 }).then(() => true, () => false)) { + await menuItem.click(); + } + })(), + ]).catch((error) => { + throw new Error("ChatGPT image download failed", { cause: error }); + }); const file = await download.path(); if (!file) throw new Error("No downloaded image"); const dimensions = body.size === "landscape" ? [1536, 1024] : [1024, 1024]; diff --git a/src/app/api/ai/image/route.ts b/src/app/api/ai/image/route.ts index 2435583..2ed9f30 100644 --- a/src/app/api/ai/image/route.ts +++ b/src/app/api/ai/image/route.ts @@ -11,6 +11,7 @@ import { assertImageQuota, generateImage } from "@/lib/ai/image"; import { IMAGE_PROMPT_MAX, IMAGE_SIZES, type ImageSizeKey } from "@/lib/ai/image-shared"; import { putBlob } from "@/lib/storage/blob"; import { logoPalettePrompt } from "@/lib/ai/brand-palette"; +import { IMAGE_ART_DIRECTION } from "@/lib/ai/prompts"; export const maxDuration = 360; @@ -26,6 +27,7 @@ const SYSTEM = `You write prompts for an AI image generator. The images illustra - No identifiable real people, celebrities or copyrighted characters. If people appear, keep them generic. - No before/after imagery and no exaggerated results (cures, guaranteed outcomes). - Follow "สีและสไตล์ภาพของแบรนด์" exactly when supplied, especially its palette, medium, lighting and exclusions. Match the shop's tone and audience through the visual mood.`; +const IMAGE_SYSTEM = `${SYSTEM}\n${IMAGE_ART_DIRECTION}`; /** * Two steps, both explicit button presses in the editor: @@ -57,7 +59,7 @@ export async function POST(req: Request) { kind: "image-prompt", pageId, userId: auth.user.id, - system: SYSTEM, + system: IMAGE_SYSTEM, prompt: `${profilePrompt(page.profile)}\n${logoPalette}\n\nWrite the image prompt for the idea below.\n\n\n${description}\n`, schema: ImagePrompt, effort: "low", diff --git a/src/app/globals.css b/src/app/globals.css index 66882c1..09f49c7 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -1302,15 +1302,16 @@ .research-actions button { margin-left: 0; } } .thai-picker-trigger { width: 100%; height: 42px; padding: 0 12px 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; text-align: start; } - .thai-picker-trigger:hover { border-color: var(--ink-3); } + .thai-picker-trigger:hover:not(:disabled) { border-color: var(--ink-3); } .thai-picker-trigger:focus-visible { outline: none; border-color: var(--m-blue); box-shadow: 0 0 0 3px var(--m-blue-soft); } .thai-picker-trigger svg { flex: none; color: var(--m-blue); } .thai-picker-trigger:disabled { cursor: not-allowed; color: var(--ink-3); background: var(--board); } - .thai-picker-popover { position: absolute; z-index: 40; right: 0; bottom: calc(100% + 8px); width: min(360px, calc(100vw - 40px)); padding: 16px; color: var(--ink); background: var(--paper); border-radius: 16px; box-shadow: var(--shadow-lift); transform-origin: bottom right; animation: thai-picker-in 160ms cubic-bezier(.23,1,.32,1); } + .thai-picker-popover { position: absolute; z-index: 40; inset-inline-end: 0; bottom: calc(100% + 8px); width: min(360px, calc(100vw - 40px)); max-height: min(520px, calc(100vh - 32px)); overflow-y: auto; overscroll-behavior: contain; padding: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lift); transform-origin: bottom right; animation: thai-picker-in 160ms ease-out; } .thai-picker-head { height: 40px; display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; margin-bottom: 8px; } .thai-picker-head strong { text-align: center; font-size: 15px; font-weight: 600; } .thai-picker-head button { width: 40px; height: 40px; border-radius: 8px; color: var(--ink-2); font-size: 27px; line-height: 1; } .thai-picker-head button:hover { color: var(--m-blue); background: var(--m-blue-soft); } + .thai-picker-head button:focus-visible, .thai-picker-grid button:focus-visible, .thai-picker-foot button:focus-visible { outline: 2px solid var(--m-blue); outline-offset: 2px; } .thai-picker-week, .thai-picker-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; } .thai-picker-week { margin-bottom: 4px; color: var(--ink-3); font-size: 11px; font-weight: 500; text-align: center; } .thai-picker-week span { display: grid; place-items: center; height: 28px; } @@ -1323,13 +1324,15 @@ .thai-picker-time select { height: 32px; padding: 0 7px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 7px; font-variant-numeric: tabular-nums; } .thai-picker-time select:first-of-type { margin-left: auto; } .thai-picker-time select:focus-visible { outline: 2px solid var(--m-blue); outline-offset: 1px; } - .thai-picker-foot { display: flex; align-items: center; justify-content: space-between; min-height: 38px; margin-top: 10px; } - .thai-picker-foot > button:first-child { min-width: 48px; min-height: 36px; color: var(--m-blue); font-weight: 500; } - .thai-picker-foot > button:first-child:hover { text-decoration: underline; text-underline-offset: 3px; } + .thai-picker-foot { display: flex; align-items: center; gap: 8px; min-height: 38px; margin-top: 10px; } + .thai-picker-foot .thai-picker-text-action { min-height: 36px; padding: 0 6px; color: var(--m-blue); font-weight: 500; } + .thai-picker-foot .thai-picker-text-action:hover { text-decoration: underline; text-underline-offset: 3px; } + .thai-picker-foot .btn { margin-left: auto; } @keyframes thai-picker-in { from { opacity: 0; transform: translateY(4px) scale(.98); } } @media (max-width: 639px) { - .thai-picker-popover { position: fixed; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); width: calc(100vw - 24px); padding: 14px; transform-origin: bottom center; } + .thai-picker-popover { position: fixed; inset-inline: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); width: auto; max-height: calc(100dvh - 100px - env(safe-area-inset-bottom)); padding: 14px; transform-origin: bottom center; } .thai-picker-trigger { height: 46px; font-size: 16px; } + .thai-picker-grid button, .thai-picker-grid > span { min-height: 40px; aspect-ratio: auto; font-size: 14px; } } @media (prefers-reduced-motion: reduce) { diff --git a/src/components/PostGenerationQueue.tsx b/src/components/PostGenerationQueue.tsx index 3d69e10..1063bda 100644 --- a/src/components/PostGenerationQueue.tsx +++ b/src/components/PostGenerationQueue.tsx @@ -13,6 +13,12 @@ function duration(job: PostJobView): string { return `${Math.floor(seconds / 60)} นาที ${seconds % 60} วินาที`; } +function formatPlannedDay(value: string): string { + const [year, month, day] = value.split("-").map(Number); + if (!year || !month || !day) return value; + return new Intl.DateTimeFormat("th-TH", { day: "numeric", month: "long", year: "numeric", timeZone: "Asia/Bangkok" }).format(new Date(Date.UTC(year, month - 1, day, -7))); +} + /** Server-persisted jobs are rediscovered after reload; the browser never executes the pipeline. */ export function PostGenerationQueue({ pageId, targets, plannedDay, initialTopic }: { pageId: string; targets: ("FACEBOOK" | "INSTAGRAM")[]; plannedDay: string; initialTopic: string; @@ -81,7 +87,7 @@ export function PostGenerationQueue({ pageId, targets, plannedDay, initialTopic หัวข้อโพสต์ที่จะเข้าคิว