@domain.js/main 1.1.2 → 1.1.4

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.
@@ -24,9 +24,15 @@ function Main(cnf, deps) {
24
24
  // Send error response
25
25
  reply.code(statusCode).send({ code, message, data });
26
26
  });
27
+ const bodyLimit = cnf.bodyMaxBytes || 10 * 1024 * 1024;
28
+ // 仅注册 MIME,使 Fastify 接受 XML 类 Content-Type(否则会 FST_ERR_CTP_INVALID_MEDIA_TYPE)。
29
+ // parseAs: "string" 只是把请求体读成原始字符串,不做 XML 结构化解析;解析由业务层按需进行。
30
+ server.addContentTypeParser(["application/xml", "text/xml", "application/rss+xml", "application/atom+xml"], { parseAs: "string", bodyLimit }, (_req, body, done) => {
31
+ done(null, body);
32
+ });
27
33
  server.register(multipart_1.default, {
28
34
  limits: {
29
- fileSize: cnf.bodyMaxBytes || 10 * 1024 * 1024, // 参数最大容量 10MB
35
+ fileSize: bodyLimit, // 参数最大容量 10MB
30
36
  },
31
37
  });
32
38
  server.register(formbody_1.default);
@@ -158,7 +158,20 @@ function Utils(cnf) {
158
158
  for await (const part of parts) {
159
159
  if (part.type === "file") {
160
160
  const saved = await RestifyFileConvertUploadFiles(part);
161
- Object.assign(files, saved);
161
+ if (!saved)
162
+ continue;
163
+ const [field, file] = saved;
164
+ if (files[field]) {
165
+ if (Array.isArray(files[field])) {
166
+ files[field].push(file);
167
+ }
168
+ else {
169
+ files[field] = [files[field], file];
170
+ }
171
+ }
172
+ else {
173
+ files[field] = file;
174
+ }
162
175
  }
163
176
  else if (part.type === "field") {
164
177
  const key = part.fieldname;
@@ -237,8 +250,7 @@ function Utils(cnf) {
237
250
  };
238
251
  async function RestifyFileConvertUploadFiles(files) {
239
252
  if (!files)
240
- return {};
241
- const result = {};
253
+ return;
242
254
  // 生成临时文件路径
243
255
  const tempFileName = `${crypto.randomBytes(16).toString("hex")}_${files.filename}`;
244
256
  const tempFilePath = `${TMPDIR}/${tempFileName}`;
@@ -261,8 +273,7 @@ function Utils(cnf) {
261
273
  type: files.mimetype,
262
274
  mtime: stats.mtime.toISOString(),
263
275
  };
264
- result[files.fieldname] = uploadFile;
265
- resolve(result);
276
+ resolve([files.fieldname, uploadFile]);
266
277
  });
267
278
  writeStream.on("error", (error) => {
268
279
  reject(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {