dff-util 1.0.4 → 1.0.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.
- package/README.md +2 -18
- package/dist/main/const-type.d.ts +4 -10
- package/dist/main/const-type.js +0 -18
- package/dist/main/http.d.ts +3 -2
- package/dist/main/http.js +23 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -196,26 +196,10 @@ export type SessionUser = {
|
|
|
196
196
|
};
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
-
##
|
|
199
|
+
## ResponseType
|
|
200
200
|
|
|
201
201
|
```
|
|
202
|
-
|
|
203
|
-
status: 0,
|
|
204
|
-
message: 'ERROR',
|
|
205
|
-
data: message
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## SuccessResponse
|
|
210
|
-
|
|
211
|
-
```
|
|
212
|
-
export const SuccessResponse = (data: any) => {
|
|
213
|
-
return {
|
|
214
|
-
status: 1,
|
|
215
|
-
type: 'SUCCESS',
|
|
216
|
-
data: data,
|
|
217
|
-
};
|
|
218
|
-
};
|
|
202
|
+
ResponseType
|
|
219
203
|
```
|
|
220
204
|
|
|
221
205
|
## file upload test
|
|
@@ -17,14 +17,8 @@ export type SessionUser = {
|
|
|
17
17
|
name?: string;
|
|
18
18
|
role: string;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
21
|
-
status
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
error: any;
|
|
25
|
-
};
|
|
26
|
-
export declare const SuccessResponse: (data: any) => {
|
|
27
|
-
status: number;
|
|
28
|
-
type: string;
|
|
29
|
-
data: any;
|
|
20
|
+
export type ResponseType = {
|
|
21
|
+
status?: string | number;
|
|
22
|
+
data?: any;
|
|
23
|
+
error?: any;
|
|
30
24
|
};
|
package/dist/main/const-type.js
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuccessResponse = exports.ErrorResponse = void 0;
|
|
4
|
-
const ErrorResponse = (message, error) => {
|
|
5
|
-
return {
|
|
6
|
-
status: 0,
|
|
7
|
-
type: 'ERROR',
|
|
8
|
-
message: message,
|
|
9
|
-
error: error,
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
exports.ErrorResponse = ErrorResponse;
|
|
13
|
-
const SuccessResponse = (data) => {
|
|
14
|
-
return {
|
|
15
|
-
status: 1,
|
|
16
|
-
type: 'SUCCESS',
|
|
17
|
-
data: data,
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
exports.SuccessResponse = SuccessResponse;
|
package/dist/main/http.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class Http {
|
|
|
23
23
|
static Put(url: string, data: any, headers: any, type?: RespType): Promise<any>;
|
|
24
24
|
static Delete(url: string, params: any, headers: any, type?: RespType): Promise<any>;
|
|
25
25
|
static Token(sessionInfo: any, appKey: string, apiKey?: string, type?: RespType): Promise<any>;
|
|
26
|
-
static
|
|
27
|
-
static
|
|
26
|
+
static FormUpload(fullUrl: string, file: File, isHeadersAddMultiForm?: boolean, data?: Record<string, any>, headers?: any, method?: 'POST' | 'PUT', type?: RespType): Promise<any>;
|
|
27
|
+
static CloudUpload(fullUrl: string, file: File, headers?: any, method?: 'POST' | 'PUT'): Promise<Response>;
|
|
28
|
+
static FileDownload(fullUrl: string, params: any, headers?: any, method?: string): Promise<Buffer>;
|
|
28
29
|
}
|
package/dist/main/http.js
CHANGED
|
@@ -126,10 +126,9 @@ class Http {
|
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
static
|
|
129
|
+
static FormUpload(fullUrl_1, file_1) {
|
|
130
130
|
return __awaiter(this, arguments, void 0, function* (fullUrl, file, isHeadersAddMultiForm = false, data = {}, headers = exports.BaseHeaders, method = 'PUT', type = RespType.JSON) {
|
|
131
131
|
const formData = new FormData();
|
|
132
|
-
console.log(file);
|
|
133
132
|
formData.append('file', file);
|
|
134
133
|
for (const key in data) {
|
|
135
134
|
if (data[key] !== undefined && data[key] !== null) {
|
|
@@ -137,7 +136,7 @@ class Http {
|
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
if (isHeadersAddMultiForm) {
|
|
140
|
-
headers = Object.assign(Object.assign({}, headers), { 'Content-Type': 'multipart/form-data' });
|
|
139
|
+
headers = Object.assign(Object.assign({}, headers), { 'Content-Type': headers['Content-Type'] || 'multipart/form-data' });
|
|
141
140
|
}
|
|
142
141
|
try {
|
|
143
142
|
const requestOptions = {
|
|
@@ -155,7 +154,27 @@ class Http {
|
|
|
155
154
|
}
|
|
156
155
|
});
|
|
157
156
|
}
|
|
158
|
-
static
|
|
157
|
+
static CloudUpload(fullUrl_1, file_1) {
|
|
158
|
+
return __awaiter(this, arguments, void 0, function* (fullUrl, file, headers = null, method = 'PUT') {
|
|
159
|
+
headers = headers || {
|
|
160
|
+
'Content-Type': file.type,
|
|
161
|
+
};
|
|
162
|
+
try {
|
|
163
|
+
const requestOptions = {
|
|
164
|
+
method: method,
|
|
165
|
+
body: file,
|
|
166
|
+
headers: Object.assign({}, headers),
|
|
167
|
+
};
|
|
168
|
+
const response = yield fetch(fullUrl, requestOptions);
|
|
169
|
+
return response;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
console.error('HttpUpload error: ', error);
|
|
173
|
+
throw { url: fullUrl, requestId: exports.HttpHeaders['x-request-id'], error: error };
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
static FileDownload(fullUrl_1, params_1) {
|
|
159
178
|
return __awaiter(this, arguments, void 0, function* (fullUrl, params, headers = exports.HttpHeaders, method = 'GET') {
|
|
160
179
|
fullUrl = params ? `${fullUrl}?${new URLSearchParams(params).toString()}` : fullUrl;
|
|
161
180
|
try {
|