chenpei 02ebaabd0e feat(外部接口): 新增自动上架成套通知能力
- 新增任务-详情全套入库后的自动上架通知与重试补发能力

- 扩展 product-assets 支持按 materialId 拉取正式资源

- 补充后台通知目标管理、投递记录和对接文档
2026-03-25 20:39:56 +08:00

53 lines
1.8 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { hasSystemAdminPermission, isSuperAdmin } from '@/lib/department-permission'
import { listExternalNotificationDeliveries } from '@/lib/external-auto-listing'
async function assertAdminPermission() {
const session = await getServerSession(authOptions)
if (!session?.user || !(session.user as any).id) {
return NextResponse.json({ success: false, error: '未登录' }, { status: 401 })
}
const userId = (session.user as any).id
const userRole = (session.user as any).role
const isSuperAdminUser = await isSuperAdmin(userId)
const hasPermission = hasSystemAdminPermission(userRole, isSuperAdminUser)
if (!hasPermission) {
return NextResponse.json({ success: false, error: '无权限访问' }, { status: 403 })
}
return null
}
export async function GET(request: NextRequest) {
try {
const authError = await assertAdminPermission()
if (authError) {
return authError
}
const { searchParams } = new URL(request.url)
const rawLimit = searchParams.get('limit')
const parsedLimit = rawLimit ? Number(rawLimit) : undefined
const limit = Number.isFinite(parsedLimit) && parsedLimit! > 0 ? parsedLimit : undefined
const deliveries = await listExternalNotificationDeliveries({
status: searchParams.get('status') || undefined,
targetId: searchParams.get('targetId') || undefined,
materialId: searchParams.get('materialId') || undefined,
limit,
})
return NextResponse.json({
success: true,
data: deliveries,
})
} catch (error) {
console.error('[admin/external-notification-deliveries] GET error:', error)
return NextResponse.json({ success: false, error: '服务器错误' }, { status: 500 })
}
}