Skip to content

Commit

Permalink
feat: busboy support async generator mode (#4074)
Browse files Browse the repository at this point in the history
* feat: support async generator mode

* fix: limit case

* fix: limit case

* fix: limit case

* chore: test case

* fix: EPIPE error

* fix: test

* fix: test

* chore: hidden init

* docs: update

* fix: file stream delay

* fix: file stream delay

(cherry picked from commit 5c54249)
  • Loading branch information
czy88840616 committed Sep 22, 2024
1 parent 97e8d71 commit d885f92
Show file tree
Hide file tree
Showing 15 changed files with 1,219 additions and 334 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ site/changelog
**/test/*.txt
.audit
pnpm-lock.yaml
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

0 comments on commit d885f92

Please sign in to comment.