@domain.js/main 1.0.0-alpha.4 → 1.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,9 @@ export declare function Utils(cnf: Cnf): {
23
23
  Querystring: Record<string, any>;
24
24
  Params: Record<string, any>;
25
25
  Body: Record<string, any>;
26
- }>): Promise<{}>;
26
+ }>): Promise<{
27
+ [x: string]: any;
28
+ }>;
27
29
  /**
28
30
  *
29
31
  * 输出csv相关
@@ -150,26 +150,42 @@ function Utils(cnf) {
150
150
  else if (req.body) {
151
151
  params.__raw = req.body;
152
152
  }
153
- // 逗号分隔的属性,自动转换为 array
154
- for (const k of str2arr) {
155
- if (params[k] && lodash_1.default.isString(params[k]))
156
- params[k] = params[k].split(",");
157
- }
158
- // 检查请求是否包含文件上传
153
+ // 处理 multipart:同时解析字段与文件
159
154
  let files = {};
160
155
  try {
161
- // 只有在 multipart 请求时才处理文件
162
156
  if ((_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.includes("multipart/form-data")) {
163
- const uploadedFile = await req.file();
164
- if (uploadedFile) {
165
- files = await RestifyFileConvertUploadFiles(uploadedFile);
157
+ const fields = {};
158
+ const parts = req.parts();
159
+ for await (const part of parts) {
160
+ if (part.type === "file") {
161
+ const saved = await RestifyFileConvertUploadFiles(part);
162
+ Object.assign(files, saved);
163
+ }
164
+ else if (part.type === "field") {
165
+ const key = part.fieldname;
166
+ const value = part.value;
167
+ if (fields[key] !== undefined) {
168
+ fields[key] = Array.isArray(fields[key])
169
+ ? [...fields[key], value]
170
+ : [fields[key], value];
171
+ }
172
+ else {
173
+ fields[key] = value;
174
+ }
175
+ }
166
176
  }
177
+ // 将表单字段合并进 params
178
+ params = { ...fields, ...params };
167
179
  }
168
180
  }
169
181
  catch (error) {
170
- // 如果文件处理出错,记录错误但不中断请求处理
171
182
  console.warn("File upload processing error:", error);
172
183
  }
184
+ // 逗号分隔的属性,自动转换为 array(在合并字段之后处理)
185
+ for (const k of str2arr) {
186
+ if (params[k] && lodash_1.default.isString(params[k]))
187
+ params[k] = params[k].split(",");
188
+ }
173
189
  // 将上传文件附加到 params 中
174
190
  return { ...params, ...files };
175
191
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {