forked from mito-systems/sol-mem-gen
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
if (!process.env.ADOBE_API_KEY || !process.env.ADOBE_CLIENT_SECRET) {
|
|
throw new Error('Adobe API credentials not configured')
|
|
}
|
|
|
|
const ADOBE_API_URL = 'https://firefly-api.adobe.io
|
|
|
|
export async function POST(req: NextRequest): Promise<NextResponse> {
|
|
try {
|
|
const { prompt } = await req.json()
|
|
|
|
if (!prompt) {
|
|
return NextResponse.json(
|
|
{ error: 'Prompt is required' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
// Adobe Firefly API request
|
|
const response = await fetch(ADOBE_API_URL, {
|
|
method: 'POST',
|
|
headers: {
|
|
'x-api-key': process.env.ADOBE_API_KEY,
|
|
'Authorization': `Bearer ${process.env.ADOBE_API_KEY}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
prompt: prompt,
|
|
n: 1,
|
|
size: { width: 1024, height: 1024 },
|
|
styles: ["default"],
|
|
seed: Math.floor(Math.random() * 1000000),
|
|
quality: "standard",
|
|
contentClass: "photo"
|
|
}),
|
|
})
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json()
|
|
console.error('Adobe API error:', errorData)
|
|
throw new Error(`Adobe API error: ${response.status}`)
|
|
}
|
|
|
|
const data = await response.json()
|
|
console.log('Adobe generation result:', data)
|
|
|
|
// Extract the image URL from the response
|
|
const imageUrl = data.outputs?.[0]?.image
|
|
|
|
if (!imageUrl) {
|
|
throw new Error('No image URL in response')
|
|
}
|
|
|
|
return NextResponse.json({ imageUrl })
|
|
} catch (error) {
|
|
console.error('Adobe generation error:', error)
|
|
return NextResponse.json(
|
|
{ error: error instanceof Error ? error.message : 'Failed to generate image' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
export const dynamic = 'force-dynamic'
|