@xuda.io/xuda-worker-bundle 1.3.2711 → 1.3.2712
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 +57 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2049,7 +2049,7 @@ func.common.db = async function (SESSION_ID, serviceP, dataP, opt = {}, dsSessio
|
|
|
2049
2049
|
throw '';
|
|
2050
2050
|
}
|
|
2051
2051
|
const is_local_draft_pouch_runtime =
|
|
2052
|
-
_session?.engine_mode
|
|
2052
|
+
['miniapp', 'live_preview'].includes(_session?.engine_mode) &&
|
|
2053
2053
|
_session?.is_draft_runtime &&
|
|
2054
2054
|
Array.isArray(_session?.rpi_http_methods) &&
|
|
2055
2055
|
_session.rpi_http_methods.includes('dbs_read');
|
|
@@ -9234,6 +9234,49 @@ func.utils.connect_pouchdb = async function (SESSION_ID) {
|
|
|
9234
9234
|
return func.utils.connect_studio_pouchdb(app_id, true);
|
|
9235
9235
|
};
|
|
9236
9236
|
|
|
9237
|
+
func.utils.base64_encode_utf8 = function (value = '') {
|
|
9238
|
+
if (typeof btoa === 'function') {
|
|
9239
|
+
return btoa(unescape(encodeURIComponent(value)));
|
|
9240
|
+
}
|
|
9241
|
+
if (typeof Buffer !== 'undefined') {
|
|
9242
|
+
return Buffer.from(value, 'utf8').toString('base64');
|
|
9243
|
+
}
|
|
9244
|
+
throw new Error('base64 encoder unavailable');
|
|
9245
|
+
};
|
|
9246
|
+
|
|
9247
|
+
func.utils.should_use_local_studio_plugin_resources = function (SESSION_ID) {
|
|
9248
|
+
const _session = SESSION_OBJ[SESSION_ID];
|
|
9249
|
+
return typeof IS_PROCESS_SERVER === 'undefined' && (['live_preview'].includes(_session?.engine_mode) || _session?.is_draft_runtime);
|
|
9250
|
+
};
|
|
9251
|
+
|
|
9252
|
+
func.utils.get_local_studio_plugin_doc = async function (SESSION_ID, plugin_name) {
|
|
9253
|
+
if (!func.utils.should_use_local_studio_plugin_resources(SESSION_ID)) {
|
|
9254
|
+
return null;
|
|
9255
|
+
}
|
|
9256
|
+
|
|
9257
|
+
try {
|
|
9258
|
+
const db = func.utils.connect_studio_pouchdb(null, false, 'xuda_studio_resources');
|
|
9259
|
+
return await db.get(plugin_name);
|
|
9260
|
+
} catch (error) {
|
|
9261
|
+
return null;
|
|
9262
|
+
}
|
|
9263
|
+
};
|
|
9264
|
+
|
|
9265
|
+
func.utils.get_local_studio_plugin_file = async function (SESSION_ID, plugin_name, resource) {
|
|
9266
|
+
const plugin_doc = await func.utils.get_local_studio_plugin_doc(SESSION_ID, plugin_name);
|
|
9267
|
+
return plugin_doc?.files?.[`${plugin_name}/${resource}`] || null;
|
|
9268
|
+
};
|
|
9269
|
+
|
|
9270
|
+
func.utils.get_local_studio_plugin_resource_url = async function (SESSION_ID, plugin_name, resource) {
|
|
9271
|
+
const file_contents = await func.utils.get_local_studio_plugin_file(SESSION_ID, plugin_name, resource);
|
|
9272
|
+
if (!file_contents) {
|
|
9273
|
+
return null;
|
|
9274
|
+
}
|
|
9275
|
+
|
|
9276
|
+
const content_type = resource.endsWith('.css') ? 'text/css' : 'text/javascript';
|
|
9277
|
+
return `data:${content_type};base64,${func.utils.base64_encode_utf8(file_contents)}`;
|
|
9278
|
+
};
|
|
9279
|
+
|
|
9237
9280
|
// func.utils.validate_pouchdb = async function (SESSION_ID) {
|
|
9238
9281
|
// const app_id = SESSION_OBJ[SESSION_ID].app_id;
|
|
9239
9282
|
// const db = new PouchDB("xuda_rt_" + app_id);
|
|
@@ -9336,6 +9379,14 @@ func.utils.get_plugin_resource = function (SESSION_ID, plugin_name, plugin_resou
|
|
|
9336
9379
|
};
|
|
9337
9380
|
|
|
9338
9381
|
return new Promise(async (resolve, reject) => {
|
|
9382
|
+
try {
|
|
9383
|
+
const local_plugin_resource_url = await func.utils.get_local_studio_plugin_resource_url(SESSION_ID, plugin_name, plugin_resource);
|
|
9384
|
+
if (local_plugin_resource_url) {
|
|
9385
|
+
const plugin_resource_res = await import(/* @vite-ignore */ local_plugin_resource_url);
|
|
9386
|
+
return resolve(plugin_resource_res);
|
|
9387
|
+
}
|
|
9388
|
+
} catch (err) {}
|
|
9389
|
+
|
|
9339
9390
|
// const db = await func.utils.connect_pouchdb(SESSION_ID);
|
|
9340
9391
|
|
|
9341
9392
|
// try {
|
|
@@ -9415,6 +9466,11 @@ func.utils.remove_cached_objects = async function (SESSION_ID) {
|
|
|
9415
9466
|
func.utils.get_plugin_npm_cdn = async function (SESSION_ID, plugin_name, resource) {
|
|
9416
9467
|
const _session = SESSION_OBJ[SESSION_ID];
|
|
9417
9468
|
|
|
9469
|
+
const local_plugin_resource_url = await func.utils.get_local_studio_plugin_resource_url(SESSION_ID, plugin_name, resource);
|
|
9470
|
+
if (local_plugin_resource_url) {
|
|
9471
|
+
return local_plugin_resource_url;
|
|
9472
|
+
}
|
|
9473
|
+
|
|
9418
9474
|
const get_path = function (resource) {
|
|
9419
9475
|
if (_session.worker_type === 'Dev') {
|
|
9420
9476
|
return `../../plugins/${plugin_name}/${resource}`;
|