Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: busboy support async generator mode #4074

Merged
merged 12 commits into from
Sep 21, 2024
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ site/changelog
.changelog
**/test/*.txt
.audit
packages/**/test/tmp
6 changes: 3 additions & 3 deletions packages/busboy/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { httpError } from '@midwayjs/core';

export class MultipartInvalidFilenameError extends httpError.BadRequestError {
constructor(filename: string) {
super(`Invalid upload file name "${filename}", please check it`);
super(`Invalid file name or suffix "${filename}".`);
}
}

export class MultipartInvalidFileTypeError extends httpError.BadRequestError {
constructor(filename: string, currentType: string, type: string) {
super(
`Invalid upload file type, "${filename}" type(${
`Invalid file type, "${filename}" type(${
currentType || 'unknown'
}) is not ${type} , please check it`
}) is not ${type}.`
);
}
}
Expand Down
22 changes: 20 additions & 2 deletions packages/busboy/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Readable } from 'stream';
import { IgnoreMatcher, IMidwayContext } from '@midwayjs/core';
import { BusboyConfig } from 'busboy';

export type UploadMode = 'stream' | 'file';
export type UploadMode = 'stream' | 'file' | 'asyncIterator';

export interface UploadOptions extends BusboyConfig {
/**
Expand Down Expand Up @@ -52,6 +52,10 @@ export interface UploadFileInfo {
* file data, a string of path
*/
data: string;
/**
* field name
*/
fieldName: string;
}

export interface UploadStreamFileInfo {
Expand All @@ -66,7 +70,21 @@ export interface UploadStreamFileInfo {
/**
* file data, Readable stream
*/
data: Readable ;
data: Readable;
/**
* field name
*/
fieldName: string;
}

export interface UploadStreamFieldInfo {
/**
* field name
*/
name: string;
/**
* field value
*/
value: any;
}

Loading
Loading