@xuda.io/drive_module 1.1.1469 → 1.1.1470

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.mjs CHANGED
@@ -1599,35 +1599,40 @@ export const run_drive_pending_ocr = async () => {
1599
1599
  }
1600
1600
  };
1601
1601
 
1602
+ const _drive_size_cache = new Map();
1603
+ const _DRIVE_SIZE_TTL_MS = 30 * 60 * 1000;
1604
+
1602
1605
  export const get_drive_size = async (req) => {
1603
1606
  try {
1604
1607
  const { drive_type, app_id, uid } = req;
1605
- let size = 0;
1608
+ const cache_key = `${drive_type}|${app_id || ''}|${uid || ''}`;
1609
+ const cached = _drive_size_cache.get(cache_key);
1610
+ if (cached && Date.now() - cached.ts < _DRIVE_SIZE_TTL_MS) {
1611
+ return { code: 200, data: cached.size };
1612
+ }
1606
1613
 
1614
+ let size = 0;
1607
1615
  let app_id_master, directoryPath;
1608
1616
  switch (drive_type) {
1609
1617
  case 'user':
1610
1618
  directoryPath = '';
1611
-
1612
1619
  break;
1613
1620
  case 'workspace':
1614
1621
  directoryPath = '';
1615
1622
  app_id_master = await _common.get_project_app_id(app_id, true);
1616
1623
  break;
1617
-
1618
1624
  default:
1619
1625
  app_id_master = await _common.get_project_app_id(app_id, true);
1620
1626
  directoryPath = path.join(_conf[`${drive_type}_drive_path`], app_id_master, '/');
1621
-
1622
1627
  break;
1623
1628
  }
1624
1629
 
1625
1630
  size = await get_folder_size(directoryPath, drive_type, app_id_master, uid);
1626
1631
  if (drive_type === 'workspace') {
1627
- // calc datacenter
1628
1632
  size += await get_folder_size(directoryPath, drive_type, app_id);
1629
1633
  }
1630
1634
 
1635
+ _drive_size_cache.set(cache_key, { size, ts: Date.now() });
1631
1636
  return { code: 200, data: size };
1632
1637
  } catch (err) {
1633
1638
  return { code: -200, data: err.message };
@@ -1731,17 +1736,31 @@ const get_folder_size = async (dir, drive_type, app_id, uid) => {
1731
1736
  let totalSize = 0;
1732
1737
 
1733
1738
  const calculateSizeFs = async (dirPath) => {
1734
- const fsPromises = fs.promises;
1735
- const files = await fsPromises.readdir(dirPath);
1736
- for (let file of files) {
1737
- const filePath = path.join(dirPath, file);
1738
- const stat = await fsPromises.stat(filePath);
1739
- if (stat.isFile()) {
1740
- totalSize += stat.size;
1741
- } else if (stat.isDirectory()) {
1742
- await calculateSizeFs(filePath);
1739
+ let entries;
1740
+ try {
1741
+ entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
1742
+ } catch (err) {
1743
+ return;
1744
+ }
1745
+ const subdirs = [];
1746
+ const file_stats = [];
1747
+ for (const entry of entries) {
1748
+ const childPath = path.join(dirPath, entry.name);
1749
+ if (entry.isDirectory()) {
1750
+ subdirs.push(childPath);
1751
+ } else if (entry.isFile()) {
1752
+ file_stats.push(
1753
+ fs.promises
1754
+ .stat(childPath)
1755
+ .then((s) => {
1756
+ totalSize += s.size;
1757
+ })
1758
+ .catch(() => {}),
1759
+ );
1743
1760
  }
1744
1761
  }
1762
+ await Promise.all(file_stats);
1763
+ await Promise.all(subdirs.map((d) => calculateSizeFs(d)));
1745
1764
  };
1746
1765
 
1747
1766
  const calculateSizeDocs = async (dirPath) => {
@@ -1991,11 +2010,22 @@ export const compile_javascript_program_in_studio_drive = async (req, job_id) =>
1991
2010
  content = ` export const css = true \n` + content;
1992
2011
  }
1993
2012
 
2013
+ const getLocalPackageName = (doc) => {
2014
+ const rawName = doc?._id || doc?.properties?.menuName || 'program';
2015
+ const safeName = String(rawName)
2016
+ .toLowerCase()
2017
+ .replace(/[^a-z0-9._-]+/g, '-')
2018
+ .replace(/^[._-]+|[._-]+$/g, '');
2019
+ const packageName = `xuda-js-program-${safeName || 'program'}`.slice(0, 214);
2020
+
2021
+ return packageName.replace(/[._-]+$/g, '') || 'xuda-js-program';
2022
+ };
2023
+
1994
2024
  const index_js = path.join(src, 'index.mjs');
1995
2025
  await fs_module.save_file(index_js, content);
1996
2026
 
1997
2027
  let packageJSON = {
1998
- name: doc.properties?.menuName || doc._id,
2028
+ name: getLocalPackageName(doc),
1999
2029
  version: '1.0.0',
2000
2030
  description: '',
2001
2031
  main: 'index.js',
@@ -2012,15 +2042,39 @@ export const compile_javascript_program_in_studio_drive = async (req, job_id) =>
2012
2042
 
2013
2043
  let devDependencies = packageJSON.devDependencies || {};
2014
2044
  let allDependencies = new Set();
2045
+ let externalImports = new Set();
2046
+
2047
+ const isUrlSpecifier = (specifier) => /^[a-z][a-z0-9+.-]*:/i.test(specifier) || specifier.startsWith('//');
2048
+
2049
+ const getPackageDependencyName = (specifier) => {
2050
+ if (!specifier) {
2051
+ return;
2052
+ }
2053
+
2054
+ if (isUrlSpecifier(specifier)) {
2055
+ externalImports.add(specifier);
2056
+ return;
2057
+ }
2058
+
2059
+ if (specifier.startsWith('.') || specifier.startsWith('/') || specifier.startsWith('#') || specifier.endsWith('.css')) {
2060
+ return;
2061
+ }
2062
+
2063
+ if (specifier.startsWith('@')) {
2064
+ const [scope, packageName] = specifier.split('/');
2065
+ return scope && packageName ? `${scope}/${packageName}` : undefined;
2066
+ }
2067
+
2068
+ return specifier.split('/')[0];
2069
+ };
2015
2070
 
2016
2071
  const extractDependencies = (fileContent, regex) => {
2017
2072
  const matches = [];
2018
2073
  let match;
2074
+ regex.lastIndex = 0;
2019
2075
  while ((match = regex.exec(fileContent)) !== null) {
2020
- let dep = match[1];
2021
- if (!dep.startsWith('.') && !dep.startsWith('/') && !dep.endsWith('.css')) {
2022
- if (dep.includes('/')) dep = dep.split('/')[0];
2023
-
2076
+ const dep = getPackageDependencyName(match[1]);
2077
+ if (dep) {
2024
2078
  matches.push(dep);
2025
2079
  }
2026
2080
  }
@@ -2062,6 +2116,7 @@ export default {
2062
2116
  name: "MyLibrary", // Global variable for UMD/IIFE formats
2063
2117
  },
2064
2118
  rollupOptions: {
2119
+ external: ${JSON.stringify(Array.from(externalImports))},
2065
2120
  output: {
2066
2121
  manualChunks(id) {
2067
2122
  if (id.includes("node_modules")) {
@@ -2221,10 +2276,10 @@ export const get_drive_files_workspace = async (req, job_id, headers, file_obj)
2221
2276
  req.drive_type = 'workspace';
2222
2277
  return await get_drive_files(req, job_id, headers, file_obj);
2223
2278
  };
2224
- export const get_drive_files_studio = async (req, job_id, headers, file_obj) => {
2279
+ export const get_drive_files_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2225
2280
  req.drive_type = 'studio';
2226
2281
  return await get_drive_files(req, job_id, headers, file_obj);
2227
- };
2282
+ });
2228
2283
  export const get_drive_files_user = async (req, job_id, headers, file_obj) => {
2229
2284
  req.drive_type = 'user';
2230
2285
  return await get_drive_files(req, job_id, headers, file_obj);
@@ -2234,10 +2289,10 @@ export const get_drive_file_info_workspace = async (req, job_id, headers, file_o
2234
2289
  req.drive_type = 'workspace';
2235
2290
  return await get_drive_file_info(req, job_id, headers, file_obj);
2236
2291
  };
2237
- export const get_drive_file_info_studio = async (req, job_id, headers, file_obj) => {
2292
+ export const get_drive_file_info_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2238
2293
  req.drive_type = 'studio';
2239
2294
  return await get_drive_file_info(req, job_id, headers, file_obj);
2240
- };
2295
+ });
2241
2296
  export const get_drive_file_info_user = async (req, job_id, headers, file_obj) => {
2242
2297
  req.drive_type = 'user';
2243
2298
  return await get_drive_file_info(req, job_id, headers, file_obj);
@@ -2247,10 +2302,10 @@ export const delete_drive_files_workspace = async (req, job_id, headers, file_ob
2247
2302
  req.drive_type = 'workspace';
2248
2303
  return await delete_drive_files(req, job_id, headers, file_obj);
2249
2304
  };
2250
- export const delete_drive_files_studio = async (req, job_id, headers, file_obj) => {
2305
+ export const delete_drive_files_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2251
2306
  req.drive_type = 'studio';
2252
2307
  return await delete_drive_files(req, job_id, headers, file_obj);
2253
- };
2308
+ });
2254
2309
  export const delete_drive_files_user = async (req, job_id, headers, file_obj) => {
2255
2310
  req.drive_type = 'user';
2256
2311
  return await delete_drive_files(req, job_id, headers, file_obj);
@@ -2260,10 +2315,10 @@ export const extract_drive_file_workspace = async (req, job_id, headers, file_ob
2260
2315
  req.drive_type = 'workspace';
2261
2316
  return await extract_drive_file(req, job_id, headers, file_obj);
2262
2317
  };
2263
- export const extract_drive_file_studio = async (req, job_id, headers, file_obj) => {
2318
+ export const extract_drive_file_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2264
2319
  req.drive_type = 'studio';
2265
2320
  return await extract_drive_file(req, job_id, headers, file_obj);
2266
- };
2321
+ });
2267
2322
  export const extract_drive_file_user = async (req, job_id, headers, file_obj) => {
2268
2323
  req.drive_type = 'user';
2269
2324
  return await extract_drive_file(req, job_id, headers, file_obj);
@@ -2273,10 +2328,10 @@ export const upload_drive_file_workspace = async (req, job_id, headers, file_obj
2273
2328
  req.drive_type = 'workspace';
2274
2329
  return await upload_drive_file(req, job_id, headers, file_obj);
2275
2330
  };
2276
- export const upload_drive_file_studio = async (req, job_id, headers, file_obj) => {
2331
+ export const upload_drive_file_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2277
2332
  req.drive_type = 'studio';
2278
2333
  return await upload_drive_file(req, job_id, headers, file_obj);
2279
- };
2334
+ });
2280
2335
  export const upload_drive_file_user = async (req, job_id, headers, file_obj) => {
2281
2336
  req.drive_type = 'user';
2282
2337
  return await upload_drive_file(req, job_id, headers, file_obj);
@@ -2286,10 +2341,10 @@ export const update_drive_file_workspace = async (req, job_id, headers, file_obj
2286
2341
  req.drive_type = 'workspace';
2287
2342
  return await update_drive_file(req, job_id, headers, file_obj);
2288
2343
  };
2289
- export const update_drive_file_studio = async (req, job_id, headers, file_obj) => {
2344
+ export const update_drive_file_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2290
2345
  req.drive_type = 'studio';
2291
2346
  return await update_drive_file(req, job_id, headers, file_obj);
2292
- };
2347
+ });
2293
2348
  export const update_drive_file_user = async (req, job_id, headers, file_obj) => {
2294
2349
  req.drive_type = 'user';
2295
2350
  return await update_drive_file(req, job_id, headers, file_obj);
@@ -2299,10 +2354,10 @@ export const create_drive_folder_workspace = async (req, job_id, headers, file_o
2299
2354
  req.drive_type = 'workspace';
2300
2355
  return await create_drive_folder(req, job_id, headers, file_obj);
2301
2356
  };
2302
- export const create_drive_folder_studio = async (req, job_id, headers, file_obj) => {
2357
+ export const create_drive_folder_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2303
2358
  req.drive_type = 'studio';
2304
2359
  return await create_drive_folder(req, job_id, headers, file_obj);
2305
- };
2360
+ });
2306
2361
  export const create_drive_folder_user = async (req, job_id, headers, file_obj) => {
2307
2362
  req.drive_type = 'user';
2308
2363
  return await create_drive_folder(req, job_id, headers, file_obj);
@@ -2312,10 +2367,10 @@ export const rename_drive_file_workspace = async (req, job_id, headers, file_obj
2312
2367
  req.drive_type = 'workspace';
2313
2368
  return await rename_drive_file(req, job_id, headers, file_obj);
2314
2369
  };
2315
- export const rename_drive_file_studio = async (req, job_id, headers, file_obj) => {
2370
+ export const rename_drive_file_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2316
2371
  req.drive_type = 'studio';
2317
2372
  return await rename_drive_file(req, job_id, headers, file_obj);
2318
- };
2373
+ });
2319
2374
  export const rename_drive_file_user = async (req, job_id, headers, file_obj) => {
2320
2375
  req.drive_type = 'user';
2321
2376
  return await rename_drive_file(req, job_id, headers, file_obj);
@@ -2325,10 +2380,10 @@ export const rename_drive_folder_workspace = async (req, job_id, headers, file_o
2325
2380
  req.drive_type = 'workspace';
2326
2381
  return await rename_drive_folder(req, job_id, headers, file_obj);
2327
2382
  };
2328
- export const rename_drive_folder_studio = async (req, job_id, headers, file_obj) => {
2383
+ export const rename_drive_folder_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2329
2384
  req.drive_type = 'studio';
2330
2385
  return await rename_drive_folder(req, job_id, headers, file_obj);
2331
- };
2386
+ });
2332
2387
  export const rename_drive_folder_user = async (req, job_id, headers, file_obj) => {
2333
2388
  req.drive_type = 'user';
2334
2389
  return await rename_drive_folder(req, job_id, headers, file_obj);
@@ -2338,10 +2393,10 @@ export const update_drive_file_sharing_mode_workspace = async (req, job_id, head
2338
2393
  req.drive_type = 'workspace';
2339
2394
  return await update_drive_file_sharing_mode(req, job_id, headers, file_obj);
2340
2395
  };
2341
- export const update_drive_file_sharing_mode_studio = async (req, job_id, headers, file_obj) => {
2396
+ export const update_drive_file_sharing_mode_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2342
2397
  req.drive_type = 'studio';
2343
2398
  return await update_drive_file_sharing_mode(req, job_id, headers, file_obj);
2344
- };
2399
+ });
2345
2400
  export const update_drive_file_sharing_mode_user = async (req, job_id, headers, file_obj) => {
2346
2401
  req.drive_type = 'user';
2347
2402
  return await update_drive_file_sharing_mode(req, job_id, headers, file_obj);
@@ -2351,10 +2406,10 @@ export const delete_file_bulk_workspace = async (req, job_id, headers, file_obj)
2351
2406
  req.drive_type = 'workspace';
2352
2407
  return await delete_file_bulk(req, job_id, headers, file_obj);
2353
2408
  };
2354
- export const delete_file_bulk_studio = async (req, job_id, headers, file_obj) => {
2409
+ export const delete_file_bulk_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2355
2410
  req.drive_type = 'studio';
2356
2411
  return await delete_file_bulk(req, job_id, headers, file_obj);
2357
- };
2412
+ });
2358
2413
  export const delete_file_bulk_user = async (req, job_id, headers, file_obj) => {
2359
2414
  req.drive_type = 'user';
2360
2415
  return await delete_file_bulk(req, job_id, headers, file_obj);
@@ -2368,14 +2423,14 @@ export const check_drive_files_workspace = async (req, job_id, headers, file_obj
2368
2423
  req.drive_type = 'workspace';
2369
2424
  return await check_drive_files(req, job_id, headers, file_obj);
2370
2425
  };
2371
- export const check_drive_file_studio = async (req, job_id, headers, file_obj) => {
2426
+ export const check_drive_file_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2372
2427
  req.drive_type = 'studio';
2373
2428
  return await check_drive_file(req, job_id, headers, file_obj);
2374
- };
2375
- export const check_drive_files_studio = async (req, job_id, headers, file_obj) => {
2429
+ });
2430
+ export const check_drive_files_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2376
2431
  req.drive_type = 'studio';
2377
2432
  return await check_drive_files(req, job_id, headers, file_obj);
2378
- };
2433
+ });
2379
2434
  export const check_drive_file_user = async (req, job_id, headers, file_obj) => {
2380
2435
  req.drive_type = 'user';
2381
2436
  return await check_drive_file(req, job_id, headers, file_obj);
@@ -2389,10 +2444,10 @@ export const update_drive_file_tags_workspace = async (req, job_id, headers, fil
2389
2444
  req.drive_type = 'workspace';
2390
2445
  return await update_drive_file_tags(req, job_id, headers, file_obj);
2391
2446
  };
2392
- export const update_drive_file_tags_studio = async (req, job_id, headers, file_obj) => {
2447
+ export const update_drive_file_tags_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2393
2448
  req.drive_type = 'studio';
2394
2449
  return await update_drive_file_tags(req, job_id, headers, file_obj);
2395
- };
2450
+ });
2396
2451
  export const update_drive_file_tags_user = async (req, job_id, headers, file_obj) => {
2397
2452
  req.drive_type = 'user';
2398
2453
  return await update_drive_file_tags(req, job_id, headers, file_obj);
@@ -2402,10 +2457,10 @@ export const update_drive_addons_workspace = async (req, job_id, headers, file_o
2402
2457
  req.drive_type = 'workspace';
2403
2458
  return await update_drive_addons(req, job_id, headers, file_obj);
2404
2459
  };
2405
- export const update_drive_addons_studio = async (req, job_id, headers, file_obj) => {
2460
+ export const update_drive_addons_studio = _common.location_sensitive(async (req, job_id, headers, file_obj) => {
2406
2461
  req.drive_type = 'studio';
2407
2462
  return await update_drive_addons(req, job_id, headers, file_obj);
2408
- };
2463
+ });
2409
2464
  export const update_drive_addons_user = async (req, job_id, headers, file_obj) => {
2410
2465
  req.drive_type = 'user';
2411
2466
  return await update_drive_addons(req, job_id, headers, file_obj);
package/index_ms.mjs CHANGED
@@ -61,6 +61,10 @@ export const upload_drive_file = async function (...args) {
61
61
  return await broker.send_to_queue("upload_drive_file", ...args);
62
62
  };
63
63
 
64
+ export const check_drive_files = async function (...args) {
65
+ return await broker.send_to_queue("check_drive_files", ...args);
66
+ };
67
+
64
68
  export const check_drive_file = async function (...args) {
65
69
  return await broker.send_to_queue("check_drive_file", ...args);
66
70
  };
@@ -229,14 +233,26 @@ export const check_drive_file_workspace = async function (...args) {
229
233
  return await broker.send_to_queue("check_drive_file_workspace", ...args);
230
234
  };
231
235
 
236
+ export const check_drive_files_workspace = async function (...args) {
237
+ return await broker.send_to_queue("check_drive_files_workspace", ...args);
238
+ };
239
+
232
240
  export const check_drive_file_studio = async function (...args) {
233
241
  return await broker.send_to_queue("check_drive_file_studio", ...args);
234
242
  };
235
243
 
244
+ export const check_drive_files_studio = async function (...args) {
245
+ return await broker.send_to_queue("check_drive_files_studio", ...args);
246
+ };
247
+
236
248
  export const check_drive_file_user = async function (...args) {
237
249
  return await broker.send_to_queue("check_drive_file_user", ...args);
238
250
  };
239
251
 
252
+ export const check_drive_files_user = async function (...args) {
253
+ return await broker.send_to_queue("check_drive_files_user", ...args);
254
+ };
255
+
240
256
  export const update_drive_file_tags_workspace = async function (...args) {
241
257
  return await broker.send_to_queue("update_drive_file_tags_workspace", ...args);
242
258
  };
package/index_msa.mjs CHANGED
@@ -61,6 +61,10 @@ export const upload_drive_file = function (...args) {
61
61
  broker.send_to_queue_async("upload_drive_file", ...args);
62
62
  };
63
63
 
64
+ export const check_drive_files = function (...args) {
65
+ broker.send_to_queue_async("check_drive_files", ...args);
66
+ };
67
+
64
68
  export const check_drive_file = function (...args) {
65
69
  broker.send_to_queue_async("check_drive_file", ...args);
66
70
  };
@@ -229,14 +233,26 @@ export const check_drive_file_workspace = function (...args) {
229
233
  broker.send_to_queue_async("check_drive_file_workspace", ...args);
230
234
  };
231
235
 
236
+ export const check_drive_files_workspace = function (...args) {
237
+ broker.send_to_queue_async("check_drive_files_workspace", ...args);
238
+ };
239
+
232
240
  export const check_drive_file_studio = function (...args) {
233
241
  broker.send_to_queue_async("check_drive_file_studio", ...args);
234
242
  };
235
243
 
244
+ export const check_drive_files_studio = function (...args) {
245
+ broker.send_to_queue_async("check_drive_files_studio", ...args);
246
+ };
247
+
236
248
  export const check_drive_file_user = function (...args) {
237
249
  broker.send_to_queue_async("check_drive_file_user", ...args);
238
250
  };
239
251
 
252
+ export const check_drive_files_user = function (...args) {
253
+ broker.send_to_queue_async("check_drive_files_user", ...args);
254
+ };
255
+
240
256
  export const update_drive_file_tags_workspace = function (...args) {
241
257
  broker.send_to_queue_async("update_drive_file_tags_workspace", ...args);
242
258
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/drive_module",
3
- "version": "1.1.1469",
3
+ "version": "1.1.1470",
4
4
  "description": "Xuda Drive Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {