41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { getServerSession } from 'next-auth'
|
|
import { NextResponse } from 'next/server'
|
|
import { authOptions } from '@/lib/auth'
|
|
import {
|
|
DingWorkflowMetricApiError,
|
|
getMonthlyLaunchSummary,
|
|
} from '@/lib/ding-workflow-sync'
|
|
|
|
export const runtime = 'nodejs'
|
|
export const dynamic = 'force-dynamic'
|
|
export const revalidate = 0
|
|
|
|
const PRIVATE_HEADERS = {
|
|
'Cache-Control': 'private, no-store, max-age=0',
|
|
}
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
const session = await getServerSession(authOptions)
|
|
const params = new URL(request.url).searchParams
|
|
const month = params.get('month')
|
|
const startDate = params.get('startDate') || params.get('start')
|
|
const endDate = params.get('endDate') || params.get('end')
|
|
const data = await getMonthlyLaunchSummary(session, { month, startDate, endDate })
|
|
return NextResponse.json({ success: true, data }, { headers: PRIVATE_HEADERS })
|
|
} catch (error) {
|
|
if (error instanceof DingWorkflowMetricApiError) {
|
|
return NextResponse.json(
|
|
{ success: false, error: error.message },
|
|
{ status: error.status, headers: PRIVATE_HEADERS },
|
|
)
|
|
}
|
|
|
|
console.error('[department-dashboard] 本月上新指标读取失败:', error)
|
|
return NextResponse.json(
|
|
{ success: false, error: '本月上新指标读取失败,请稍后重试' },
|
|
{ status: 500, headers: PRIVATE_HEADERS },
|
|
)
|
|
}
|
|
}
|