49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
import { revealNotificationCenterProjectSecret } from '@/lib/notification-center-admin'
|
|
import {
|
|
requireNotificationCenterSuperAdmin,
|
|
toNotificationCenterAdminErrorResponse,
|
|
} from '../../../_shared'
|
|
|
|
export const runtime = 'nodejs'
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
const NO_STORE_HEADERS = {
|
|
'Cache-Control': 'no-store, max-age=0',
|
|
Pragma: 'no-cache',
|
|
}
|
|
|
|
function withNoStore(response: NextResponse) {
|
|
for (const [name, value] of Object.entries(NO_STORE_HEADERS)) {
|
|
response.headers.set(name, value)
|
|
}
|
|
return response
|
|
}
|
|
|
|
export async function POST(
|
|
_request: NextRequest,
|
|
{ params }: { params: { code: string } },
|
|
) {
|
|
try {
|
|
const auth = await requireNotificationCenterSuperAdmin()
|
|
if ('response' in auth) return withNoStore(auth.response)
|
|
|
|
const code = String(params?.code || '').trim()
|
|
if (!code) {
|
|
return NextResponse.json(
|
|
{ success: false, error: '通知中心项目不存在' },
|
|
{ status: 404, headers: NO_STORE_HEADERS },
|
|
)
|
|
}
|
|
|
|
const result = await revealNotificationCenterProjectSecret(auth.actor, code)
|
|
return NextResponse.json(
|
|
{ success: true, data: result.data },
|
|
{ status: result.status, headers: NO_STORE_HEADERS },
|
|
)
|
|
} catch (error) {
|
|
return withNoStore(toNotificationCenterAdminErrorResponse(error))
|
|
}
|
|
}
|