dff-util 1.0.0 → 1.0.2

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.
@@ -10,6 +10,10 @@ export declare const HttpHeaders: {
10
10
  authorization: null;
11
11
  'x-request-id': null;
12
12
  };
13
+ export declare const BaseHeaders: {
14
+ authorization: null;
15
+ 'x-request-id': null;
16
+ };
13
17
  export declare class Http {
14
18
  static API_BASE_URL: string | undefined;
15
19
  static TOKEN_URL: string;
@@ -18,7 +22,7 @@ export declare class Http {
18
22
  static Post(url: string, data: any, headers: any, type?: RespType): Promise<any>;
19
23
  static Put(url: string, data: any, headers: any, type?: RespType): Promise<any>;
20
24
  static Delete(url: string, params: any, headers: any, type?: RespType): Promise<any>;
21
- static Token(sessionInfo: any, key: string, type?: RespType): Promise<any>;
22
- static Upload(fullUrl: string, file: File, data?: Record<string, any>, headers?: any, type?: RespType): Promise<any>;
25
+ static Token(sessionInfo: any, appKey: string, apiKey?: string, type?: RespType): Promise<any>;
26
+ static Upload(fullUrl: string, file: File, isHeadersAddMultiForm?: boolean, data?: Record<string, any>, headers?: any, type?: RespType): Promise<any>;
23
27
  static Download(fullUrl: string, params: any, headers?: any): Promise<Buffer>;
24
28
  }
package/dist/main/http.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Http = exports.HttpHeaders = exports.RespType = void 0;
12
+ exports.Http = exports.BaseHeaders = exports.HttpHeaders = exports.RespType = void 0;
13
13
  var RespType;
14
14
  (function (RespType) {
15
15
  RespType["JSON"] = "json";
@@ -23,6 +23,10 @@ exports.HttpHeaders = {
23
23
  authorization: null,
24
24
  'x-request-id': null,
25
25
  };
26
+ exports.BaseHeaders = {
27
+ authorization: null,
28
+ 'x-request-id': null,
29
+ };
26
30
  class Http {
27
31
  static RespData(response_1) {
28
32
  return __awaiter(this, arguments, void 0, function* (response, type = RespType.JSON) {
@@ -105,13 +109,14 @@ class Http {
105
109
  }
106
110
  });
107
111
  }
108
- static Token(sessionInfo_1, key_1) {
109
- return __awaiter(this, arguments, void 0, function* (sessionInfo, key, type = RespType.TEXT) {
112
+ static Token(sessionInfo_1, appKey_1, apiKey_1) {
113
+ return __awaiter(this, arguments, void 0, function* (sessionInfo, appKey, apiKey, type = RespType.TEXT) {
110
114
  const url = `${Http.API_BASE_URL}${Http.TOKEN_URL}`;
111
- const params = { key: key, payload: JSON.stringify(sessionInfo) };
115
+ const params = { key: appKey, payload: JSON.stringify(sessionInfo) };
112
116
  const fullUrl = `${url}?${new URLSearchParams(params).toString()}`;
117
+ const headers = Object.assign(Object.assign({}, Headers), { 'X-API-KEY': apiKey || '' });
113
118
  try {
114
- const requestOptions = { method: 'GET', headers: exports.HttpHeaders };
119
+ const requestOptions = { method: 'GET', headers: headers };
115
120
  const response = yield fetch(fullUrl, requestOptions);
116
121
  return yield Http.RespData(response, type);
117
122
  }
@@ -122,20 +127,25 @@ class Http {
122
127
  });
123
128
  }
124
129
  static Upload(fullUrl_1, file_1) {
125
- return __awaiter(this, arguments, void 0, function* (fullUrl, file, data = {}, headers = exports.HttpHeaders, type = RespType.JSON) {
130
+ return __awaiter(this, arguments, void 0, function* (fullUrl, file, isHeadersAddMultiForm = false, data = {}, headers = exports.BaseHeaders, type = RespType.JSON) {
126
131
  const formData = new FormData();
132
+ console.log(file);
127
133
  formData.append('file', file);
128
134
  for (const key in data) {
129
135
  if (data[key] !== undefined && data[key] !== null) {
130
136
  formData.append(key, data[key]);
131
137
  }
132
138
  }
139
+ if (isHeadersAddMultiForm) {
140
+ headers = Object.assign(Object.assign({}, headers), { 'Content-Type': 'multipart/form-data' });
141
+ }
133
142
  try {
134
143
  const requestOptions = {
135
144
  method: 'POST',
136
145
  body: formData,
137
- headers: Object.assign(Object.assign({}, headers), { 'Content-Type': 'multipart/form-data' }),
146
+ headers: Object.assign({}, headers),
138
147
  };
148
+ console.log(requestOptions);
139
149
  const response = yield fetch(fullUrl, requestOptions);
140
150
  return yield Http.RespData(response, type);
141
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dff-util",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {