Skip to content

Commit 392c61c

Browse files
fengmk2claude
andcommitted
refactor(multipart): replace co-busboy with @eggjs/co-busboy
- Update multipart plugin to use the new @eggjs/co-busboy package - Import Part type for proper type narrowing - Add truncated property to FileStream interface - Fix type assertions for AsyncIterable return 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 379106b commit 392c61c

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

packages/co-busboy/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export interface FileStream extends Readable {
2828
transferEncoding: string;
2929
mime: string;
3030
mimeType: string;
31+
/**
32+
* Set by busboy when file size limit is reached
33+
*/
34+
truncated?: boolean;
3135
}
3236

3337
/**
@@ -94,6 +98,10 @@ export interface Parts {
9498
(): Promise<Part | null>;
9599
field: Record<string, string | string[]>;
96100
fields: FieldTuple[];
101+
/**
102+
* Allow adding async iterator at runtime for for-await-of support
103+
*/
104+
[Symbol.asyncIterator]?: () => AsyncIterator<Part>;
97105
}
98106

99107
/**

plugins/multipart/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
"typecheck": "tsgo --noEmit"
6060
},
6161
"dependencies": {
62+
"@eggjs/co-busboy": "workspace:*",
6263
"@eggjs/path-matching": "workspace:*",
6364
"bytes": "catalog:",
64-
"co-busboy": "catalog:",
6565
"dayjs": "catalog:"
6666
},
6767
"devDependencies": {

plugins/multipart/src/app/extend/context.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import path from 'node:path';
66
import { Readable, PassThrough } from 'node:stream';
77
import { pipeline } from 'node:stream/promises';
88

9-
// @ts-expect-error no types
10-
import parse from 'co-busboy';
9+
import { parse, type Part } from '@eggjs/co-busboy';
1110
import dayjs from 'dayjs';
1211
import { Context } from 'egg';
1312

@@ -120,7 +119,7 @@ export default class MultipartContext extends Context {
120119
// mount asyncIterator, so we can use `for await` to get parts
121120
const parts = parse(this, parseOptions);
122121
parts[Symbol.asyncIterator] = async function* () {
123-
let part: MultipartFileStream | undefined;
122+
let part: Part | null;
124123
do {
125124
part = await parts();
126125

@@ -157,10 +156,10 @@ export default class MultipartContext extends Context {
157156
}
158157

159158
// dispatch part to outter logic such as for-await-of
160-
yield part;
161-
} while (part !== undefined);
159+
yield part as MultipartFileStream;
160+
} while (part !== null);
162161
};
163-
return parts;
162+
return parts as unknown as AsyncIterable<MultipartFileStream>;
164163
}
165164

166165
/**

pnpm-lock.yaml

Lines changed: 3 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)