refactor(api): move 2 forward methods to ForwardApi (#6 commit 9/13)
Inlines `actions/forward.ts` into `apis/forward.ts::ForwardApi`. The
file is the largest unmoved one — 475 lines covering long-message
upload with NapCat-style piggyback for nested {type:"node"} chains,
plus the cached fetch side.
The module-scoped `forwardResCache` Map stays at file scope rather
than as an instance field. Forward res_ids are globally unique and
an outbound upload often gets queried back through `fetch` on a
different Bridge instance (different OneBot connection hitting the
same account) — NapCat's behaviour relies on the cache being shared
across the process.
Method renaming (Api namespace already says "forward"):
uploadForwardNodes → upload
fetchForwardNodes → fetch
The private `uploadForwardNodesRecursive` becomes
`this.uploadRecursive(...)` — same body, threads through `this.ctx`.
Callers updated: `modules/message-actions.ts` (4 sites).
Tests rewritten:
- `forward.test.ts` → `new ForwardApi(bridge as any).upload/fetch(...)`
- `forward-file.test.ts` → same pattern
- `forward-nested.test.ts` → mocks `apis.forward.upload` instead of
flat `bridge.uploadForwardNodes`
587/587 tests pass.
This commit is contained in:
1 parent
62c5590fe1
commit
d953b9824c
9 files changed
+523
-510
No files matched your search
@@ -46,7 +46,7 @@ vi.mock('../../src/bridge/element-builder', () => ({
|
||||
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendLongMsgResp } from '@snowluma/proto-defs/longmsg';
|
||||
import * as forward from '../../src/bridge/actions/forward';
|
||||
import { ForwardApi } from '../../src/bridge/apis/forward';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
function uploadResponseWithResId(resId: string) {
|
||||
@@ -70,7 +70,7 @@ describe('actions/forward — file segment inside forward node', () => {
|
||||
sendRawPacket: vi.fn(async () => uploadResponseWithResId('res-grp-file')) as any,
|
||||
});
|
||||
|
||||
await forward.uploadForwardNodes(bridge as any, [
|
||||
await new ForwardApi(bridge as any).upload([
|
||||
{
|
||||
userUin: 10001,
|
||||
nickname: 'alice',
|
||||
@@ -100,7 +100,7 @@ describe('actions/forward — file segment inside forward node', () => {
|
||||
recallUploadedFile: vi.fn(() => undefined),
|
||||
});
|
||||
|
||||
await forward.uploadForwardNodes(bridge as any, [
|
||||
await new ForwardApi(bridge as any).upload([
|
||||
{
|
||||
userUin: 10001,
|
||||
nickname: 'alice',
|
||||
@@ -157,7 +157,7 @@ describe('actions/forward — file segment inside forward node', () => {
|
||||
recallUploadedFile,
|
||||
});
|
||||
|
||||
await forward.uploadForwardNodes(bridge as any, [{
|
||||
await new ForwardApi(bridge as any).upload([{
|
||||
userUin: 10001,
|
||||
nickname: 'alice',
|
||||
elements: [{ type: 'file', fileId: 'pfid-cached' } as any],
|
||||
|
||||
Reference in new issue
Block a user