Skip to content

Commit

Permalink
fix: use @eggjs/multipart
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 3, 2025
1 parent 15c5e5d commit 3addb1c
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 12 deletions.
1 change: 0 additions & 1 deletion index-old.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
// BaseContextClass as CoreBaseContextClass,
// } from 'egg-core';
// import EggCookies = require('egg-cookies');
// import 'egg-multipart';
// import 'egg-view';

// declare module 'egg' {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@eggjs/i18n": "^3.0.1",
"@eggjs/jsonp": "^3.0.0",
"@eggjs/logrotator": "^4.0.0",
"@eggjs/multipart": "^4.0.0",
"@eggjs/onerror": "^3.0.0",
"@eggjs/schedule": "^5.0.2",
"@eggjs/security": "^4.0.0",
Expand All @@ -37,7 +38,6 @@
"cluster-client": "^3.7.0",
"egg-errors": "^2.3.2",
"egg-logger": "^3.6.1",
"egg-multipart": "^3.5.0",
"egg-view": "^2.1.4",
"extend2": "^4.0.0",
"graceful": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions site/docs/basics/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ If user request exceeds the maximum length for parsing that we configured, the f

### Acquiring the Submitted Files

The `body` in the request can carry parameters as well as files. Generally speaking, our browsers always send files in `multipart/form-data`, and we now have two kinds of ways supporting submitting and acquiring files with the help of the framework's plugin [Multipart](https://github.com/eggjs/egg-multipart).
The `body` in the request can carry parameters as well as files. Generally speaking, our browsers always send files in `multipart/form-data`, and we now have two kinds of ways supporting submitting and acquiring files with the help of the framework's plugin [Multipart](https://github.com/eggjs/multipart).

- #### `File` Mode:
If you have no ideas about Nodejs's Stream at all, the `File` mode suits you well:
Expand Down Expand Up @@ -589,7 +589,7 @@ module.exports = {

**Notice:`fileExtensions` will be IGNORED when `whitelist` is overwritten.**

For more tech details about this, please refer [Egg-Multipart](https://github.com/eggjs/egg-multipart).
For more tech details about this, please refer [@eggjs/multipart](https://github.com/eggjs/multipart).

### `header`

Expand Down
6 changes: 4 additions & 2 deletions site/docs/basics/controller.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ module.exports = {
**注意:调整 bodyParser 支持的 body 长度时,如果应用之前有一层反向代理(如 Nginx),同样需要调整配置确保支持相等长度的请求 body。**

**常见错误:将 `ctx.request.body``ctx.body` 混淆,后者实际上是 `ctx.response.body` 的简写。**

### 获取上传的文件

请求体除了可以带参数之外,还可以发送文件。通常情况下,浏览器会通过 `Multipart/form-data` 格式发送文件。通过内置的 [Multipart](https://github.com/eggjs/egg-multipart) 插件,框架支持获取用户上传的文件。我们为你提供了两种方式:
请求体除了可以带参数之外,还可以发送文件。通常情况下,浏览器会通过 `Multipart/form-data` 格式发送文件。通过内置的 [Multipart](https://github.com/eggjs/multipart) 插件,框架支持获取用户上传的文件。我们为你提供了两种方式:

#### File 模式

Expand Down Expand Up @@ -579,7 +580,8 @@ module.exports = {

**注意:当重写了 whitelist 时,fileExtensions 不生效。**

欲了解更多有关的技术细节和信息,请参阅 [Egg-Multipart](https://github.com/eggjs/egg-multipart)
欲了解更多有关的技术细节和信息,请参阅 [@eggjs/multipart](https://github.com/eggjs/multipart)

### Header

除了从 URL 和请求 body 上获取参数之外,还有许多参数是通过请求 header 传递的。框架提供了一些辅助属性和方法来获取:
Expand Down
2 changes: 1 addition & 1 deletion site/docs/basics/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Specific consolidation rules can be found in [Configuration](./config.md).
  - [session](https://github.com/eggjs/session) Session implementation
  - [i18n](https://github.com/eggjs/i18n) Multilingual
  - [watcher](https://github.com/eggjs/watcher) File and folder monitoring
  - [multipart](https://github.com/eggjs/egg-multipart) File Streaming Upload
  - [multipart](https://github.com/eggjs/multipart) File Streaming Upload
  - [security](https://github.com/eggjs/security) Security
  - [development](https://github.com/eggjs/development) Development Environment Configuration
  - [logrotator](https://github.com/eggjs/logrotator) Log segmentation
Expand Down
2 changes: 1 addition & 1 deletion site/docs/basics/plugin.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ exports.mysql = {
- [session](https://github.com/eggjs/session) Session 实现
- [i18n](https://github.com/eggjs/i18n) 多语言
- [watcher](https://github.com/eggjs/watcher) 文件和文件夹监控
- [multipart](https://github.com/eggjs/egg-multipart) 文件流式上传
- [multipart](https://github.com/eggjs/multipart) 文件流式上传
- [security](https://github.com/eggjs/security) 安全
- [development](https://github.com/eggjs/development) 开发环境配置
- [logrotator](https://github.com/eggjs/logrotator) 日志切分
Expand Down
2 changes: 1 addition & 1 deletion site/docs/intro/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ while ((part = await parts()) != null) {
}
```

- [egg-multipart#upload-multiple-files](https://github.com/eggjs/egg-multipart#upload-multiple-files)
- [egg-multipart#upload-multiple-files](https://github.com/eggjs/multipart#upload-multiple-files)

### egg-userrole

Expand Down
2 changes: 1 addition & 1 deletion site/docs/intro/migration.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ while ((part = await parts()) != null) {
}
```

- [egg-multipart#upload-multiple-files](https://github.com/eggjs/egg-multipart#upload-multiple-files)
- [egg-multipart#upload-multiple-files](https://github.com/eggjs/multipart#upload-multiple-files)

### egg-userrole

Expand Down
2 changes: 1 addition & 1 deletion src/app/extend/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Request extends EggCoreRequest {
declare response: Response;

/**
* Request body, parsed from koa-bodyparser or egg-multipart
* Request body, parsed from koa-bodyparser or @eggjs/multipart
*/
declare body: any;

Expand Down
2 changes: 1 addition & 1 deletion src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
*/
multipart: {
enable: true,
package: 'egg-multipart',
package: '@eggjs/multipart',
},

/**
Expand Down
15 changes: 15 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import '@eggjs/schedule';
import '@eggjs/session';
import '@eggjs/onerror';
import '@eggjs/logrotator';
import '@eggjs/multipart';

export type {
EggAppInfo,
Expand Down Expand Up @@ -81,6 +82,20 @@ export interface HttpClientConfig {
useHttpClientNext?: boolean;
}

/**
* Powerful Partial, Support adding ? modifier to a mapped property in deep level
* @example
* import { PowerPartial, EggAppConfig } from 'egg';
*
* // { view: { defaultEngines: string } } => { view?: { defaultEngines?: string } }
* type EggConfig = PowerPartial<EggAppConfig>
*/
export type PowerPartial<T> = {
[U in keyof T]?: T[U] extends object
? PowerPartial<T[U]>
: T[U]
};

export interface EggAppConfig extends EggCoreAppConfig {
workerStartTimeout: number;
baseDir: string;
Expand Down
7 changes: 7 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ expectType<boolean>(app.config.logrotator.gzip);
expectType<string>(app.config.logrotator.hourDelimiter);
expectType<string[] | null>(app.config.logrotator.filesRotateBySize);

// multipart plugin types
expectType<boolean>(app.config.multipart.cleanSchedule.disable);
expectType<string>(app.config.multipart.cleanSchedule.cron);
expectType<string>(app.config.multipart.defaultCharset);
expectType<'file' | 'stream'>(app.config.multipart.mode);


class AppBoot implements ILifecycleBoot {
private readonly app: Application;

Expand Down

0 comments on commit 3addb1c

Please sign in to comment.