diff --git a/index-old.d.ts b/index-old.d.ts index cfe28f351c..4e48b26f4f 100644 --- a/index-old.d.ts +++ b/index-old.d.ts @@ -32,7 +32,6 @@ // BaseContextClass as CoreBaseContextClass, // } from 'egg-core'; // import EggCookies = require('egg-cookies'); -// import 'egg-multipart'; // import 'egg-view'; // declare module 'egg' { diff --git a/package.json b/package.json index a65f0f1c3d..526993ed05 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/site/docs/basics/controller.md b/site/docs/basics/controller.md index ab57aefe71..b6d07c95d0 100644 --- a/site/docs/basics/controller.md +++ b/site/docs/basics/controller.md @@ -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: @@ -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` diff --git a/site/docs/basics/controller.zh-CN.md b/site/docs/basics/controller.zh-CN.md index d92008a7af..173263806a 100644 --- a/site/docs/basics/controller.zh-CN.md +++ b/site/docs/basics/controller.zh-CN.md @@ -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 模式 @@ -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 传递的。框架提供了一些辅助属性和方法来获取: diff --git a/site/docs/basics/plugin.md b/site/docs/basics/plugin.md index 0bc414d0ea..c53adc7c2e 100644 --- a/site/docs/basics/plugin.md +++ b/site/docs/basics/plugin.md @@ -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 diff --git a/site/docs/basics/plugin.zh-CN.md b/site/docs/basics/plugin.zh-CN.md index f91922d10c..ca8252ad9c 100644 --- a/site/docs/basics/plugin.zh-CN.md +++ b/site/docs/basics/plugin.zh-CN.md @@ -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) 日志切分 diff --git a/site/docs/intro/migration.md b/site/docs/intro/migration.md index 214a66d30f..e490d9a68d 100644 --- a/site/docs/intro/migration.md +++ b/site/docs/intro/migration.md @@ -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 diff --git a/site/docs/intro/migration.zh-CN.md b/site/docs/intro/migration.zh-CN.md index 6003c015c2..d8b4cf84a2 100644 --- a/site/docs/intro/migration.zh-CN.md +++ b/site/docs/intro/migration.zh-CN.md @@ -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 diff --git a/src/app/extend/request.ts b/src/app/extend/request.ts index e4819768ef..9ac515278d 100644 --- a/src/app/extend/request.ts +++ b/src/app/extend/request.ts @@ -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; diff --git a/src/config/plugin.ts b/src/config/plugin.ts index 094bca10b6..0d583245e0 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -50,7 +50,7 @@ export default { */ multipart: { enable: true, - package: 'egg-multipart', + package: '@eggjs/multipart', }, /** diff --git a/src/lib/types.ts b/src/lib/types.ts index d560d1cd95..6c03ab88b3 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -27,6 +27,7 @@ import '@eggjs/schedule'; import '@eggjs/session'; import '@eggjs/onerror'; import '@eggjs/logrotator'; +import '@eggjs/multipart'; export type { EggAppInfo, @@ -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 + */ +export type PowerPartial = { + [U in keyof T]?: T[U] extends object + ? PowerPartial + : T[U] +}; + export interface EggAppConfig extends EggCoreAppConfig { workerStartTimeout: number; baseDir: string; diff --git a/test/index.test-d.ts b/test/index.test-d.ts index fdc5f48b83..9b0f4004c9 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -85,6 +85,13 @@ expectType(app.config.logrotator.gzip); expectType(app.config.logrotator.hourDelimiter); expectType(app.config.logrotator.filesRotateBySize); +// multipart plugin types +expectType(app.config.multipart.cleanSchedule.disable); +expectType(app.config.multipart.cleanSchedule.cron); +expectType(app.config.multipart.defaultCharset); +expectType<'file' | 'stream'>(app.config.multipart.mode); + + class AppBoot implements ILifecycleBoot { private readonly app: Application;