esoftplay 0.0.129-e → 0.0.129-g

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.
Files changed (2) hide show
  1. package/modules/lib/curl.ts +28 -10
  2. package/package.json +1 -1
@@ -10,7 +10,7 @@ import { reportApiError } from "esoftplay/error";
10
10
  import esp from 'esoftplay/esp';
11
11
  import Constants from 'expo-constants';
12
12
 
13
- //api_logger_import
13
+ import { LogStateProperty } from 'esoftplay/cache/log/state/import';
14
14
 
15
15
 
16
16
  const { manifest } = Constants;
@@ -127,6 +127,22 @@ export default class m {
127
127
  return true
128
128
  }
129
129
 
130
+ private objectToURLParams(obj: any, parentKey = ''): string[] {
131
+ let urlParams: string[] = [];
132
+
133
+ for (const key in obj) {
134
+ if (typeof obj[key] === 'object') {
135
+ const newKey = parentKey ? `${parentKey}[${key}]` : key;
136
+ urlParams.push(...this.objectToURLParams(obj[key], newKey));
137
+ } else {
138
+ const paramKey = parentKey ? `${parentKey}[${key}]` : key;
139
+ const paramValue = encodeURIComponent(obj[key]);
140
+ urlParams.push(`${paramKey}=${paramValue}`);
141
+ }
142
+ }
143
+ return urlParams;
144
+ }
145
+
130
146
  public secure(token_uri?: string): (apiKey?: string) => (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (error: any, timeout: boolean) => void, debug?: number) => void {
131
147
  return (apiKey?: string): (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (error: any, timeout: boolean) => void, debug?: number) => void => {
132
148
  return async (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (error: any, timeout: boolean) => void, debug?: number) => {
@@ -146,7 +162,7 @@ export default class m {
146
162
  _post.api_key = _apiKey
147
163
  post.api_key = _apiKey
148
164
  }
149
- let ps = Object.keys(_post).map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(_post[key])).join('&');
165
+ let ps = this.objectToURLParams(_post).join('&')
150
166
  var options: any = {
151
167
  method: "POST",
152
168
  signal: this.signal,
@@ -258,9 +274,7 @@ export default class m {
258
274
  const str: any = LibNet_status.state().get()
259
275
  if (str.isOnline) {
260
276
  if (post) {
261
- let ps = Object.keys(post).map((key) => {
262
- return encodeURIComponent(key) + '=' + encodeURIComponent(post[key]);
263
- }).join('&');
277
+ let ps = this.objectToURLParams(post).join('&')
264
278
  this.post = ps
265
279
  }
266
280
  this.setUri(uri)
@@ -302,7 +316,10 @@ export default class m {
302
316
  LibProgress.hide()
303
317
  this.onError(resText)
304
318
  }
305
- //api_logger
319
+ if (LogStateProperty) {
320
+ var resJson = typeof resText == 'string' && ((resText.startsWith("{") && resText.endsWith("}")) || (resText.startsWith("[") && resText.endsWith("]"))) ? JSON.parse(resText) : resText
321
+ LogStateProperty.doLogCurl(this.uri, this.url, post, this.isSecure, resJson)
322
+ }
306
323
  }).catch((e) => {
307
324
  this.cancelTimeout()
308
325
  LibProgress.hide()
@@ -322,9 +339,7 @@ export default class m {
322
339
  });
323
340
  this.post = fd
324
341
  } else {
325
- let ps = Object.keys(post).map((key) => {
326
- return encodeURIComponent(key) + '=' + encodeURIComponent(post[key]);
327
- }).join('&');
342
+ let ps = this.objectToURLParams(post).join('&')
328
343
  this.post = ps
329
344
  }
330
345
  }
@@ -366,7 +381,10 @@ export default class m {
366
381
  if (onFailed) onFailed({ message: esp.lang("lib/curl", "msg_failed") }, false)
367
382
  return
368
383
  }
369
- //api_logger
384
+ if (LogStateProperty) {
385
+ var resJson = typeof resText == 'string' && ((resText.startsWith("{") && resText.endsWith("}")) || (resText.startsWith("[") && resText.endsWith("]"))) ? JSON.parse(resText) : resText
386
+ LogStateProperty.doLogCurl(this.uri, this.url, post, this.isSecure, resJson)
387
+ }
370
388
  this.onFetched(resText, onDone, onFailed, debug)
371
389
  }).catch((r) => {
372
390
  // if (this.maxRetry > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.129-e",
3
+ "version": "0.0.129-g",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",