@xuda.io/xuda-worker-bundle-min 1.3.352 → 1.3.354

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/index.js +72 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -266,7 +266,7 @@ func.common.db = async function (
266
266
 
267
267
  data.req_id = new Date().valueOf();
268
268
 
269
- const perform_rpi_request = function (serviceP) {
269
+ const perform_rpi_request = async function (serviceP) {
270
270
  var url = func.common.get_url(SESSION_ID, "rpi", "");
271
271
 
272
272
  if (
@@ -278,29 +278,45 @@ func.common.db = async function (
278
278
 
279
279
  url += serviceP;
280
280
 
281
- fetch(url, {
282
- method: opt.type ? opt.type : "POST",
283
- headers: {
284
- Accept: "application/json",
285
- "Content-Type": "application/json",
286
- },
287
- body: JSON.stringify(data),
288
- })
289
- .then((response) => {
290
- if (!response.ok) {
291
- return response.text().then((text) => {
292
- throw new Error(text);
293
- });
294
- }
295
- return response.json();
296
- })
297
- .then((json) => {
298
- success_callback(json, true);
299
- })
300
- .catch((err) => {
301
- error_callback(err);
302
- console.error(err);
281
+ try {
282
+ const response = await fetch(url, {
283
+ method: opt.type ? opt.type : "POST",
284
+ headers: {
285
+ Accept: "application/json",
286
+ "Content-Type": "application/json",
287
+ },
288
+ body: JSON.stringify(data),
303
289
  });
290
+ if (!response.ok) throw "";
291
+ const json = await response.json();
292
+ return json.data;
293
+ } catch (err) {
294
+ console.error(err);
295
+ }
296
+
297
+ // fetch(url, {
298
+ // method: opt.type ? opt.type : "POST",
299
+ // headers: {
300
+ // Accept: "application/json",
301
+ // "Content-Type": "application/json",
302
+ // },
303
+ // body: JSON.stringify(data),
304
+ // })
305
+ // .then((response) => {
306
+ // if (!response.ok) {
307
+ // return response.text().then((text) => {
308
+ // throw new Error(text);
309
+ // });
310
+ // }
311
+ // return response.json();
312
+ // })
313
+ // .then((json) => {
314
+ // success_callback(json, true);
315
+ // })
316
+ // .catch((err) => {
317
+ // error_callback(err);
318
+ // console.error(err);
319
+ // });
304
320
  };
305
321
 
306
322
  // const perform_rpi_request_from_studio = async function (serviceP) {
@@ -348,8 +364,32 @@ func.common.db = async function (
348
364
  // };
349
365
 
350
366
  const perform_rpi_request_from_pouch = async function (serviceP) {
351
- const ret = await func.db[serviceP](SESSION_ID, dataP);
352
- return ret;
367
+ const db = await func.utils.connect_pouchdb(SESSION_ID);
368
+ const rep_id = JSON.stringify(dataP);
369
+ var ret;
370
+ try {
371
+ const doc = await db.get(rep_id);
372
+ if (doc.stat < 3) throw "replication not ready";
373
+ const json = await func.db.pouch[serviceP](SESSION_ID, dataP);
374
+ return success_callback(json, true);
375
+ } catch (err) {
376
+ try {
377
+ const json = await perform_rpi_request(serviceP);
378
+
379
+ try {
380
+ await db.put({
381
+ _id: rep_id,
382
+ selector: json.opt.selector,
383
+ stat: 1,
384
+ ts: Date.now(),
385
+ });
386
+ } catch (err) {}
387
+
388
+ return success_callback(json, true);
389
+ } catch (err) {
390
+ return error_callback(err);
391
+ }
392
+ }
353
393
  };
354
394
 
355
395
  if (
@@ -369,7 +409,13 @@ func.common.db = async function (
369
409
  };
370
410
  return success_callback(ret);
371
411
  }
372
- return perform_rpi_request(serviceP);
412
+ try {
413
+ const json = await perform_rpi_request(serviceP);
414
+ return success_callback(json, true);
415
+ } catch (err) {
416
+ return error_callback(err);
417
+ }
418
+ // return perform_rpi_request(serviceP);
373
419
  }
374
420
 
375
421
  // if (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle-min",
3
- "version": "1.3.352",
3
+ "version": "1.3.354",
4
4
  "description": "xuda framework min",
5
5
  "main": "index.js",
6
6
  "scripts": {