chenpei 9cd3c0f231 feat: 任务详情无条码开关 + 上传面板信息密度优化 + 历史导入/脚本补全
- 任务详情上传支持"本批素材无条码"开关,跳过条码必填校验
- SKU卡片/主图网格从4列改5列,图片高度压缩,去掉冗余标签和提示
- 详情图/PSD上传区去掉大占位框,改成紧凑按钮+标签
- 补充历史导入相关脚本和工具文件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-11 10:01:08 +08:00

108 lines
2.5 KiB
TypeScript

/**
* 任务-详情上传完成接口(改造版)
* POST - 打包文件、生成预览图、保存资产信息
*/
import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { prisma } from '@/lib/prisma'
import { completeProductPackageUpload } from '@/lib/product-package-completion'
export const runtime = 'nodejs'
export const dynamic = 'force-dynamic'
export const maxDuration = 10800
interface AssetUpload {
uploadId?: string
fileUrl?: string
fileName: string
fileSize: number
sortOrder?: number
skuCode?: string
barcodes?: string[]
}
interface PsdAsset {
uploadId?: string
fileUrl?: string
fileName: string
fileSize: number
}
interface CompleteRequestBody {
materialId: string
taskNo?: string
noBarcodes?: boolean
assets: {
main?: AssetUpload[]
sku?: AssetUpload[]
detail?: AssetUpload[]
psd?: PsdAsset[]
}
}
export async function POST(request: NextRequest) {
try {
const session = await getServerSession(authOptions)
if (!session?.user || !(session.user as any).id) {
return NextResponse.json(
{ success: false, error: '未登录' },
{ status: 401 },
)
}
const body: CompleteRequestBody = await request.json()
const material = await prisma.material.findUnique({
where: { id: body.materialId },
select: {
id: true,
userId: true,
},
})
if (!material) {
return NextResponse.json(
{ success: false, error: '素材不存在' },
{ status: 404 },
)
}
if (material.userId !== (session.user as any).id) {
return NextResponse.json(
{ success: false, error: '无权限操作此素材' },
{ status: 403 },
)
}
const result = await completeProductPackageUpload({
materialId: body.materialId,
taskNo: body.taskNo,
assets: body.assets,
operatorUserId: (session.user as any).id,
options: {
allowSkuWithoutBarcodes: body.noBarcodes === true,
},
})
return NextResponse.json({
success: true,
data: {
materialId: result.materialId,
taskNo: result.taskNo,
isFullSet: result.isFullSet,
message: '上传完成',
},
})
} catch (error) {
console.error('[Product Package Complete] Error:', error)
return NextResponse.json(
{
success: false,
error: error instanceof Error ? error.message : '服务器错误',
},
{ status: 500 },
)
}
}