From 72a9ac8fe867459543883b5ae14649612943374e Mon Sep 17 00:00:00 2001 From: Il Harper Date: Mon, 27 May 2024 20:56:41 +0800 Subject: [PATCH] feat(shell): add `chronocat.putongdejiekou1` api def --- packages/shell/src/satori/routes/index.ts | 2 ++ .../src/satori/routes/putongdejiekou/1.ts | 30 +++++++++++++++++++ .../src/satori/types/satoriPayloadEntity.ts | 7 +++++ .../src/satori/types/satoriPayloadRich.ts | 1 + packages/shell/src/types.ts | 3 ++ 5 files changed, 43 insertions(+) create mode 100644 packages/shell/src/satori/routes/putongdejiekou/1.ts diff --git a/packages/shell/src/satori/routes/index.ts b/packages/shell/src/satori/routes/index.ts index d297151..b241b27 100644 --- a/packages/shell/src/satori/routes/index.ts +++ b/packages/shell/src/satori/routes/index.ts @@ -20,6 +20,7 @@ import { messageDelete } from './message/delete' import { messageGet } from './message/get' import { messageList } from './message/list' import { notImplemented } from './notimpl' +import { puTongDeJieKou1 } from './putongdejiekou/1' import type { Route } from './types' import { userChannelCreate } from './user/channel/create' import { userGet } from './user/get' @@ -63,6 +64,7 @@ const routesIntl = { 'friend.list': friendList, 'friend.approve': friendApprove, 'unsafe.friend.remove': friendRemove, + 'chronocat.putongdejiekou1': puTongDeJieKou1, } as const export type Routes = keyof typeof routesIntl diff --git a/packages/shell/src/satori/routes/putongdejiekou/1.ts b/packages/shell/src/satori/routes/putongdejiekou/1.ts new file mode 100644 index 0000000..227cae4 --- /dev/null +++ b/packages/shell/src/satori/routes/putongdejiekou/1.ts @@ -0,0 +1,30 @@ +import type { PuTongDeJieKou1Payload } from '../../types' +import type { RouteContext } from '../types' + +export const puTongDeJieKou1 = async ({ + cctx, + path, + req, + res, + json, +}: RouteContext) => { + const payload = (await json()) as PuTongDeJieKou1Payload + + const validateResult = await cctx.chronocat.validate( + 'PuTongDeJieKou1Payload', + )(payload) + + if (validateResult) { + const err = `解析 ${path} 请求时出现问题,来自 ${req.socket.remoteAddress}。${validateResult}` + + cctx.chronocat.l.error(err, { + code: 400, + }) + + res.writeHead(400) + res.end(`400 bad request\n${err}`) + return + } + + return await cctx.chronocat.api['chronocat.putongdejiekou1'](payload) +} diff --git a/packages/shell/src/satori/types/satoriPayloadEntity.ts b/packages/shell/src/satori/types/satoriPayloadEntity.ts index 939252d..8da02bf 100644 --- a/packages/shell/src/satori/types/satoriPayloadEntity.ts +++ b/packages/shell/src/satori/types/satoriPayloadEntity.ts @@ -165,3 +165,10 @@ export interface GuildMemberTitleSetPayload { */ title?: string } + +export interface PuTongDeJieKou1Payload { + g: string + a: string + b: string + d: string +} diff --git a/packages/shell/src/satori/types/satoriPayloadRich.ts b/packages/shell/src/satori/types/satoriPayloadRich.ts index 452098d..295bb59 100644 --- a/packages/shell/src/satori/types/satoriPayloadRich.ts +++ b/packages/shell/src/satori/types/satoriPayloadRich.ts @@ -23,6 +23,7 @@ export type { MessageListPayload, MessageListResponse, Next, + PuTongDeJieKou1Payload, UserGetPayload, UserPayload, } from './satoriPayloadEntity' diff --git a/packages/shell/src/types.ts b/packages/shell/src/types.ts index 673c458..a1ad1b9 100644 --- a/packages/shell/src/types.ts +++ b/packages/shell/src/types.ts @@ -32,6 +32,7 @@ import type { MessageListPayload, MessageListResponse, Next, + PuTongDeJieKou1Payload, User, UserGetPayload, UserPayload, @@ -137,6 +138,8 @@ export interface SatoriMethods { 'friend.list': [[Next], FriendListResponse] 'friend.approve': [[ApprovePayload], Record] 'unsafe.friend.remove': [[UserPayload], Record] + + 'chronocat.putongdejiekou1': [[PuTongDeJieKou1Payload], Record] } export interface CCInternalMethods {