Skip to content

Commit 3addb1c

Browse files
committed
fix: use @eggjs/multipart
1 parent 15c5e5d commit 3addb1c

File tree

12 files changed

+35
-12
lines changed

12 files changed

+35
-12
lines changed

index-old.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
// BaseContextClass as CoreBaseContextClass,
3333
// } from 'egg-core';
3434
// import EggCookies = require('egg-cookies');
35-
// import 'egg-multipart';
3635
// import 'egg-view';
3736

3837
// declare module 'egg' {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@eggjs/i18n": "^3.0.1",
2727
"@eggjs/jsonp": "^3.0.0",
2828
"@eggjs/logrotator": "^4.0.0",
29+
"@eggjs/multipart": "^4.0.0",
2930
"@eggjs/onerror": "^3.0.0",
3031
"@eggjs/schedule": "^5.0.2",
3132
"@eggjs/security": "^4.0.0",
@@ -37,7 +38,6 @@
3738
"cluster-client": "^3.7.0",
3839
"egg-errors": "^2.3.2",
3940
"egg-logger": "^3.6.1",
40-
"egg-multipart": "^3.5.0",
4141
"egg-view": "^2.1.4",
4242
"extend2": "^4.0.0",
4343
"graceful": "^2.0.0",

site/docs/basics/controller.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ If user request exceeds the maximum length for parsing that we configured, the f
315315

316316
### Acquiring the Submitted Files
317317

318-
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).
318+
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).
319319

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

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

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

594594
### `header`
595595

site/docs/basics/controller.zh-CN.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,10 @@ module.exports = {
311311
**注意:调整 bodyParser 支持的 body 长度时,如果应用之前有一层反向代理(如 Nginx),同样需要调整配置确保支持相等长度的请求 body。**
312312

313313
**常见错误:将 `ctx.request.body``ctx.body` 混淆,后者实际上是 `ctx.response.body` 的简写。**
314+
314315
### 获取上传的文件
315316

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

318319
#### File 模式
319320

@@ -579,7 +580,8 @@ module.exports = {
579580

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

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

585587
除了从 URL 和请求 body 上获取参数之外,还有许多参数是通过请求 header 传递的。框架提供了一些辅助属性和方法来获取:

site/docs/basics/plugin.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Specific consolidation rules can be found in [Configuration](./config.md).
164164
  - [session](https://github.com/eggjs/session) Session implementation
165165
  - [i18n](https://github.com/eggjs/i18n) Multilingual
166166
  - [watcher](https://github.com/eggjs/watcher) File and folder monitoring
167-
  - [multipart](https://github.com/eggjs/egg-multipart) File Streaming Upload
167+
  - [multipart](https://github.com/eggjs/multipart) File Streaming Upload
168168
  - [security](https://github.com/eggjs/security) Security
169169
  - [development](https://github.com/eggjs/development) Development Environment Configuration
170170
  - [logrotator](https://github.com/eggjs/logrotator) Log segmentation

site/docs/basics/plugin.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ exports.mysql = {
164164
- [session](https://github.com/eggjs/session) Session 实现
165165
- [i18n](https://github.com/eggjs/i18n) 多语言
166166
- [watcher](https://github.com/eggjs/watcher) 文件和文件夹监控
167-
- [multipart](https://github.com/eggjs/egg-multipart) 文件流式上传
167+
- [multipart](https://github.com/eggjs/multipart) 文件流式上传
168168
- [security](https://github.com/eggjs/security) 安全
169169
- [development](https://github.com/eggjs/development) 开发环境配置
170170
- [logrotator](https://github.com/eggjs/logrotator) 日志切分

site/docs/intro/migration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ while ((part = await parts()) != null) {
6060
}
6161
```
6262

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

6565
### egg-userrole
6666

site/docs/intro/migration.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ while ((part = await parts()) != null) {
6161
}
6262
```
6363

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

6666
### egg-userrole
6767

src/app/extend/request.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class Request extends EggCoreRequest {
1717
declare response: Response;
1818

1919
/**
20-
* Request body, parsed from koa-bodyparser or egg-multipart
20+
* Request body, parsed from koa-bodyparser or @eggjs/multipart
2121
*/
2222
declare body: any;
2323

src/config/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default {
5050
*/
5151
multipart: {
5252
enable: true,
53-
package: 'egg-multipart',
53+
package: '@eggjs/multipart',
5454
},
5555

5656
/**

src/lib/types.ts

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import '@eggjs/schedule';
2727
import '@eggjs/session';
2828
import '@eggjs/onerror';
2929
import '@eggjs/logrotator';
30+
import '@eggjs/multipart';
3031

3132
export type {
3233
EggAppInfo,
@@ -81,6 +82,20 @@ export interface HttpClientConfig {
8182
useHttpClientNext?: boolean;
8283
}
8384

85+
/**
86+
* Powerful Partial, Support adding ? modifier to a mapped property in deep level
87+
* @example
88+
* import { PowerPartial, EggAppConfig } from 'egg';
89+
*
90+
* // { view: { defaultEngines: string } } => { view?: { defaultEngines?: string } }
91+
* type EggConfig = PowerPartial<EggAppConfig>
92+
*/
93+
export type PowerPartial<T> = {
94+
[U in keyof T]?: T[U] extends object
95+
? PowerPartial<T[U]>
96+
: T[U]
97+
};
98+
8499
export interface EggAppConfig extends EggCoreAppConfig {
85100
workerStartTimeout: number;
86101
baseDir: string;

test/index.test-d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ expectType<boolean>(app.config.logrotator.gzip);
8585
expectType<string>(app.config.logrotator.hourDelimiter);
8686
expectType<string[] | null>(app.config.logrotator.filesRotateBySize);
8787

88+
// multipart plugin types
89+
expectType<boolean>(app.config.multipart.cleanSchedule.disable);
90+
expectType<string>(app.config.multipart.cleanSchedule.cron);
91+
expectType<string>(app.config.multipart.defaultCharset);
92+
expectType<'file' | 'stream'>(app.config.multipart.mode);
93+
94+
8895
class AppBoot implements ILifecycleBoot {
8996
private readonly app: Application;
9097

0 commit comments

Comments
 (0)