Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/api/ai/headlines/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createClient } from '@/lib/supabase/server'
import { getSupabaseAdmin } from '@/lib/supabase/admin'
import { generateHeadlines } from '@/lib/ai/claude'
import { brandProfileToMetadataConfig, generateHeadlines } from '@/lib/ai/claude'
import { checkUsage, incrementUsage } from '@/lib/utils/rate-limit'
import {
handleApiError,
Expand Down Expand Up @@ -32,12 +32,23 @@ export async function POST(request: Request) {
throw new UsageLimitError('AI 헤드라인', usage.limit)
}

const promptConfig = body.promptConfig ?? (
body.brandStyleDirection || body.brandKeywords?.length
? brandProfileToMetadataConfig({
platform: body.platform,
styleDirection: body.brandStyleDirection,
keywords: body.brandKeywords,
})
: undefined
)

const result = await generateHeadlines({
projectName: body.projectName,
description: body.description,
platform: body.platform,
brandKeywords: body.brandKeywords,
brandStyleDirection: body.brandStyleDirection,
promptConfig,
})

await incrementUsage(getSupabaseAdmin(), user.id, 'ai_headlines_used_this_month')
Expand Down
36 changes: 31 additions & 5 deletions app/api/assets/generate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ export async function POST(request: Request) {

const project = projectData as Project

const { data: startedProject, error: startError } = await supabase
.from('projects')
.update({ status: 'generating', pipeline_stage: 'icon_resolve' })
.eq('id', projectId)
.eq('user_id', user.id)
Comment on lines +49 to +53

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Move generating status update after prerequisite checks

The project is marked status='generating' before validating dependent records (for example, the style preset lookup just below). If that lookup fails (missing/deleted preset or query error), the handler throws before entering the pipeline try/catch that resets status, leaving the row stuck as generating; later generate attempts then return ASSET_GENERATION_IN_PROGRESS even though no pipeline is running.

Useful? React with 👍 / 👎.

.neq('status', 'generating')
.select('id')
.maybeSingle()

if (startError) {
throw new AppError(
startError.message,
'ASSET_GENERATION_START_FAILED',
500,
'에셋 생성을 시작하지 못했습니다. 잠시 후 다시 시도해주세요.'
)
}

if (!startedProject) {
return Response.json(
{
success: false,
error: {
code: 'ASSET_GENERATION_IN_PROGRESS',
message: '이미 에셋 생성이 진행 중입니다.',
},
},
{ status: 409 }
)
}

let brandProfile: BrandProfile | null = null
if (project.brand_profile_id) {
const { data: brandData } = await supabase
Expand All @@ -68,11 +99,6 @@ export async function POST(request: Request) {

const stylePreset = presetData as StylePreset

await supabase
.from('projects')
.update({ status: 'generating', pipeline_stage: 'icon_resolve' })
.eq('id', projectId)

try {
const startedAt = Date.now()
const { storageUrl, warnings } = await runAssetPipeline({
Expand Down
2 changes: 1 addition & 1 deletion components/wizard/step-5-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function Step5Preview({
document.body.removeChild(link)
}

if (status === 'generating' || status === 'idle') {
if (status === 'generating') {
return <GeneratingState progress={progress} stage={stage} />
}

Expand Down
1 change: 0 additions & 1 deletion components/wizard/wizard-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export function WizardShell({ brandProfiles, stylePresets, user }: WizardShellPr
})

setProjectId(project.id)
store.reset()
nextStep()
} catch {
setSaveError(tErrors('projectSaveUnknownError'))
Expand Down
Loading