@xuda.io/xuda-worker-bundle-min 1.3.351 → 1.3.353
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/index.js +68 -25
- 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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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,7 +364,28 @@ func.common.db = async function (
|
|
|
348
364
|
// };
|
|
349
365
|
|
|
350
366
|
const perform_rpi_request_from_pouch = async function (serviceP) {
|
|
351
|
-
const
|
|
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
|
+
ret = await func.db.pouch[serviceP](SESSION_ID, dataP);
|
|
374
|
+
} catch (err) {
|
|
375
|
+
ret = await perform_rpi_request();
|
|
376
|
+
try {
|
|
377
|
+
await db.put({
|
|
378
|
+
_id: rep_id,
|
|
379
|
+
selector: ret.opt.selector,
|
|
380
|
+
stat: 1,
|
|
381
|
+
ts: Date.now(),
|
|
382
|
+
});
|
|
383
|
+
} catch (err) {}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return ret;
|
|
387
|
+
|
|
388
|
+
const ret = await func.db.pouch[serviceP](SESSION_ID, dataP);
|
|
352
389
|
return ret;
|
|
353
390
|
};
|
|
354
391
|
|
|
@@ -369,7 +406,13 @@ func.common.db = async function (
|
|
|
369
406
|
};
|
|
370
407
|
return success_callback(ret);
|
|
371
408
|
}
|
|
372
|
-
|
|
409
|
+
try {
|
|
410
|
+
const json = await perform_rpi_request(serviceP);
|
|
411
|
+
return success_callback(json, true);
|
|
412
|
+
} catch (err) {
|
|
413
|
+
return error_callback(err);
|
|
414
|
+
}
|
|
415
|
+
// return perform_rpi_request(serviceP);
|
|
373
416
|
}
|
|
374
417
|
|
|
375
418
|
// if (
|