flnxi-Wu/app/api/ai/edit/route.ts
WuYongJie f646b71813
Some checks failed
CI Check / check (push) Has been cancelled
chore: 初始化本地仓库并同步最近改动
2025-11-18 17:50:16 +08:00

52 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { featureFlags } from '@/lib/config'
import { prisma } from '@/lib/prisma'
async function ensureAiEditEnabled() {
if (featureFlags.aiEditEnabled) return true
const settings = await prisma.systemSettings.findFirst({
select: { enableAiImageEdit: true },
})
return !!settings?.enableAiImageEdit
}
export async function POST(req: NextRequest) {
try {
const session = await getServerSession(authOptions)
if (!session) {
return NextResponse.json({ error: '未登录' }, { status: 401 })
}
const isEnabled = await ensureAiEditEnabled()
if (!isEnabled) {
return NextResponse.json({ error: 'AI改图功能未启用' }, { status: 501 })
}
const body = await req.json().catch(() => ({}))
const { materialId, operation, params } = body || {}
if (!materialId || !operation) {
return NextResponse.json({ error: '缺少必要参数(materialId/operation)' }, { status: 400 })
}
// TODO: 校验用户是否有权限访问该素材(上传者或其上级)
// TODO: 接入外部AI服务(基于你提供的API),并以任务形式异步执行
return NextResponse.json({
message: 'AI改图任务创建成功(占位)',
taskId: 'mock_task_id',
materialId,
operation,
params: params || {},
status: 'queued',
})
} catch (error) {
console.error('AI Edit Error:', error)
return NextResponse.json({ error: '服务异常' }, { status: 500 })
}
}