@cnbcool/cnb-api-generate 2.9.3 → 2.10.0

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.
package/client/core.ts CHANGED
@@ -43,6 +43,8 @@ async function formatResponse(data: any, response: any) {
43
43
  const pageSize = response.headers.get('x-cnb-page-size');
44
44
  const total = response.headers.get('x-cnb-total');
45
45
 
46
+ const contentType = response.headers.get('content-type') || '';
47
+
46
48
  const responseData: {
47
49
  status: number;
48
50
  trace?: string;
@@ -51,6 +53,7 @@ async function formatResponse(data: any, response: any) {
51
53
  pageSize?: number;
52
54
  total?: number;
53
55
  totalPages?: number;
56
+ contentType?: string;
54
57
  data: Record<string, any> | string | null;
55
58
  } = {
56
59
  status,
@@ -60,6 +63,7 @@ async function formatResponse(data: any, response: any) {
60
63
  'x-cnb-page-size': pageSize,
61
64
  'x-cnb-total': total,
62
65
  },
66
+ contentType: contentType || undefined,
63
67
  data: null,
64
68
  };
65
69
 
@@ -74,7 +78,6 @@ async function formatResponse(data: any, response: any) {
74
78
  responseData.totalPages = Math.ceil(totalNum / pageSizeNum);
75
79
  }
76
80
 
77
- const contentType = response.headers.get('content-type') || '';
78
81
  const isJson = [
79
82
  'application/vnd.cnb.api+json',
80
83
  'application/json',
@@ -25,6 +25,11 @@ export function compactResponse(response: any): any {
25
25
  compact.totalPages = response.totalPages;
26
26
  }
27
27
 
28
+ // 保留 contentType(下载文件时有用)
29
+ if (response.contentType) {
30
+ compact.contentType = response.contentType;
31
+ }
32
+
28
33
  compact.data = response.data;
29
34
  return compact;
30
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-api-generate",
3
- "version": "2.9.3",
3
+ "version": "2.10.0",
4
4
  "main": "./built/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",