dff-util 1.0.1 → 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.
- package/dist/main/http.d.ts +5 -1
- package/dist/main/http.js +12 -3
- package/package.json +1 -1
package/dist/main/http.d.ts
CHANGED
|
@@ -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;
|
|
@@ -19,6 +23,6 @@ export declare class Http {
|
|
|
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
25
|
static Token(sessionInfo: any, appKey: string, apiKey?: string, type?: RespType): Promise<any>;
|
|
22
|
-
static Upload(fullUrl: string, file: File, data?: Record<string, any>, headers?: any, 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) {
|
|
@@ -123,20 +127,25 @@ class Http {
|
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
129
|
static Upload(fullUrl_1, file_1) {
|
|
126
|
-
return __awaiter(this, arguments, void 0, function* (fullUrl, file, data = {}, headers = exports.
|
|
130
|
+
return __awaiter(this, arguments, void 0, function* (fullUrl, file, isHeadersAddMultiForm = false, data = {}, headers = exports.BaseHeaders, type = RespType.JSON) {
|
|
127
131
|
const formData = new FormData();
|
|
132
|
+
console.log(file);
|
|
128
133
|
formData.append('file', file);
|
|
129
134
|
for (const key in data) {
|
|
130
135
|
if (data[key] !== undefined && data[key] !== null) {
|
|
131
136
|
formData.append(key, data[key]);
|
|
132
137
|
}
|
|
133
138
|
}
|
|
139
|
+
if (isHeadersAddMultiForm) {
|
|
140
|
+
headers = Object.assign(Object.assign({}, headers), { 'Content-Type': 'multipart/form-data' });
|
|
141
|
+
}
|
|
134
142
|
try {
|
|
135
143
|
const requestOptions = {
|
|
136
144
|
method: 'POST',
|
|
137
145
|
body: formData,
|
|
138
|
-
headers: Object.assign(
|
|
146
|
+
headers: Object.assign({}, headers),
|
|
139
147
|
};
|
|
148
|
+
console.log(requestOptions);
|
|
140
149
|
const response = yield fetch(fullUrl, requestOptions);
|
|
141
150
|
return yield Http.RespData(response, type);
|
|
142
151
|
}
|