21 lines
1.1 KiB
TypeScript
21 lines
1.1 KiB
TypeScript
import { assertSameOrigin, authFailure, AuthError, jsonResponse, readJsonObject, requireApiUser } from '@/lib/server/auth';
|
|||
|
|
import { feishuStatus, parseFeishuDeliveryQuery, retryFeishuNotification, testFeishuBot } from '@/lib/server/feishu-notifications';
|
||
|
|
|
||
|
|
export const runtime = 'nodejs';
|
||
|
|
export const dynamic = 'force-dynamic';
|
||
|
|
export async function GET(request: Request) {
|
||
|
|
try { await requireApiUser({ admin: true }); return jsonResponse(feishuStatus(parseFeishuDeliveryQuery(new URL(request.url).searchParams))); }
|
||
|
|
catch (error) { return authFailure(error); }
|
||
|
|
}
|
||
|
|
export async function POST(request: Request) {
|
||
|
|
try {
|
||
|
|
assertSameOrigin(request);
|
||
|
|
await requireApiUser({ admin: true });
|
||
|
|
const query = parseFeishuDeliveryQuery(new URL(request.url).searchParams);
|
||
|
|
const body = await readJsonObject(request);
|
||
|
|
if (body.action === 'test') await testFeishuBot();
|
||
|
|
else if (body.action === 'retry') retryFeishuNotification(body.id);
|
||
|
|
else throw new AuthError('不支持的操作。');
|
||
|
|
return jsonResponse(feishuStatus(query));
|
||
|
|
} catch (error) { return authFailure(error); }
|
||
|
|
}
|