dff-util 1.0.5 → 1.0.7

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 CHANGED
@@ -196,26 +196,15 @@ export type SessionUser = {
196
196
  };
197
197
  ```
198
198
 
199
- ## ErrorResponse
199
+ ## ResponseType
200
200
 
201
201
  ```
202
- new ErrorResponse(message): {
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
- };
202
+ ResponseType = {
203
+ status?: string | number;
204
+ data?: any;
205
+ error?: any;
218
206
  };
207
+
219
208
  ```
220
209
 
221
210
  ## file upload test
@@ -17,14 +17,8 @@ export type SessionUser = {
17
17
  name?: string;
18
18
  role: string;
19
19
  };
20
- export declare const ErrorResponse: (message: string, error?: any) => {
21
- status: number;
22
- type: string;
23
- message: string;
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
  };
@@ -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;
@@ -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 Upload(fullUrl: string, file: File, isHeadersAddMultiForm?: boolean, data?: Record<string, any>, headers?: any, method?: 'POST' | 'PUT', type?: RespType): Promise<any>;
27
- static Download(fullUrl: string, params: any, headers?: any, method?: string): Promise<Buffer>;
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 Upload(fullUrl_1, file_1) {
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) {
@@ -155,7 +154,27 @@ class Http {
155
154
  }
156
155
  });
157
156
  }
158
- static Download(fullUrl_1, params_1) {
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dff-util",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {