Files
NapCatQQ/packages/napcat-onebot/action/stream/TestStreamDownload.ts
T
吴天一 deae7fd467 fix: 对齐 OneBot schema 与合并转发消息处理行为 (#1694)
* fix: make defaulted request fields optional

* fix: align onebot schemas with runtime behavior

* fix: tighten schema and unsupported action metadata

* fix: reject empty forward reference ids

* fix: update GoCQHTTPSendForwardMsg to handle messages correctly and adjust payload schema

* fix: refactor message handling in GoCQHTTPSendForwardMsg and add test for message normalization

* fix: update compatibility actions to return appropriate responses and align schemas with runtime behavior

* fix: ensure payload properties are non-null with default values in action handlers

* fix: update StreamStatus comments for clarity and enforce nickname as required in message schema

* fix: integrate sleep function in GetOnlineClient and update tests to verify API call

* fix: add production test checklist for OneBot schema alignment and message handling

* fix: remove outdated production test checklist for OneBot schema alignment
2026-03-12 01:54:33 +08:00

44 lines
1.6 KiB
TypeScript

import { ActionName } from '@/napcat-onebot/action/router';
import { OneBotAction, OneBotRequestToolkit } from '@/napcat-onebot/action/OneBotAction';
import { Static, Type } from '@sinclair/typebox';
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
import { StreamPacket, StreamStatus } from './StreamBasic';
export const TestDownloadStreamPayloadSchema = Type.Object({
error: Type.Optional(Type.Boolean({ default: false, description: '是否触发测试错误' })),
});
export type TestDownloadStreamPayload = Static<typeof TestDownloadStreamPayloadSchema>;
export class TestDownloadStream extends OneBotAction<TestDownloadStreamPayload, StreamPacket<{ data: string; }>> {
override actionName = ActionName.TestDownloadStream;
override actionSummary = '测试下载流';
override actionTags = ['流式传输扩展'];
override payloadExample = {
error: false,
};
override returnExample = {
success: true,
};
override payloadSchema = TestDownloadStreamPayloadSchema;
override returnSchema = Type.Any({ description: '测试流数据' });
override useStream = true;
async _handle (_payload: TestDownloadStreamPayload, _adaptername: string, _config: NetworkAdapterConfig, req: OneBotRequestToolkit) {
for (let i = 0; i < 10; i++) {
await req.send({ type: StreamStatus.Stream, data: `Index-> ${i + 1}`, data_type: 'data_chunk' });
await new Promise(resolve => setTimeout(resolve, 100));
}
if (_payload.error) {
throw new Error('This is a test error');
}
return {
type: StreamStatus.Response,
data_type: 'data_complete',
data: 'Stream transmission complete',
};
}
}