@xuda.io/drive_module 1.1.1374 → 1.1.1376
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 +106 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1673,7 +1673,8 @@ const get_folder_size = async (dir, drive_type, app_id, uid) => {
|
|
|
1673
1673
|
};
|
|
1674
1674
|
let ret;
|
|
1675
1675
|
if (drive_type === 'user') {
|
|
1676
|
-
opt.selector.uid = uid;
|
|
1676
|
+
// opt.selector.uid = uid;
|
|
1677
|
+
const account_module = await import(`${module_path}/account_module/index.mjs`);
|
|
1677
1678
|
const app_id = await account_module.get_account_default_project_id(uid);
|
|
1678
1679
|
ret = await db_module.find_app_couch_query(app_id, opt);
|
|
1679
1680
|
} else {
|
|
@@ -2318,3 +2319,107 @@ export const update_drive_addons_user = async (req, job_id, headers, file_obj) =
|
|
|
2318
2319
|
req.drive_type = 'user';
|
|
2319
2320
|
return await update_drive_addons(req, job_id, headers, file_obj);
|
|
2320
2321
|
};
|
|
2322
|
+
|
|
2323
|
+
export const file_upload_validator = function (file_name) {
|
|
2324
|
+
// 1. Safety check: ensure file_name exists
|
|
2325
|
+
if (!file_name || typeof file_name !== 'string') {
|
|
2326
|
+
return { valid: false, error: 'Invalid filename' };
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
// 2. Extract the extension (remove dot and make lowercase)
|
|
2330
|
+
const ext = file_name.split('.').pop().toLowerCase();
|
|
2331
|
+
|
|
2332
|
+
// 3. Validate using Switch
|
|
2333
|
+
switch (ext) {
|
|
2334
|
+
// ==============================
|
|
2335
|
+
// VALIDATE AUDIO FILES
|
|
2336
|
+
// ==============================
|
|
2337
|
+
case 'mp3':
|
|
2338
|
+
return { valid: true, category: 'audio', mime: 'audio/mpeg' };
|
|
2339
|
+
case 'wav':
|
|
2340
|
+
return { valid: true, category: 'audio', mime: 'audio/wav' };
|
|
2341
|
+
case 'ogg':
|
|
2342
|
+
return { valid: true, category: 'audio', mime: 'audio/ogg' };
|
|
2343
|
+
case 'm4a':
|
|
2344
|
+
return { valid: true, category: 'audio', mime: 'audio/mp4' };
|
|
2345
|
+
|
|
2346
|
+
// ==============================
|
|
2347
|
+
// VALIDATE VIDEO FILES
|
|
2348
|
+
// ==============================
|
|
2349
|
+
case 'mp4':
|
|
2350
|
+
return { valid: true, category: 'video', mime: 'video/mp4' };
|
|
2351
|
+
case 'webm':
|
|
2352
|
+
return { valid: true, category: 'video', mime: 'video/webm' };
|
|
2353
|
+
case 'avi':
|
|
2354
|
+
return { valid: true, category: 'video', mime: 'video/x-msvideo' };
|
|
2355
|
+
case 'mov':
|
|
2356
|
+
return { valid: true, category: 'video', mime: 'video/quicktime' };
|
|
2357
|
+
|
|
2358
|
+
// ==============================
|
|
2359
|
+
// VALIDATE PICTURE FILES
|
|
2360
|
+
// ==============================
|
|
2361
|
+
case 'jpg':
|
|
2362
|
+
case 'jpeg':
|
|
2363
|
+
return { valid: true, category: 'image', mime: 'image/jpeg' };
|
|
2364
|
+
case 'png':
|
|
2365
|
+
return { valid: true, category: 'image', mime: 'image/png' };
|
|
2366
|
+
case 'gif':
|
|
2367
|
+
return { valid: true, category: 'image', mime: 'image/gif' };
|
|
2368
|
+
case 'svg':
|
|
2369
|
+
return { valid: true, category: 'image', mime: 'image/svg+xml' };
|
|
2370
|
+
case 'webp':
|
|
2371
|
+
return { valid: true, category: 'image', mime: 'image/webp' };
|
|
2372
|
+
|
|
2373
|
+
// ==============================
|
|
2374
|
+
// VALIDATE TEXT / CODE FILES
|
|
2375
|
+
// ==============================
|
|
2376
|
+
case 'c':
|
|
2377
|
+
return { valid: true, category: 'text', mime: 'text/x-c' };
|
|
2378
|
+
case 'cpp':
|
|
2379
|
+
return { valid: true, category: 'text', mime: 'text/x-c++' };
|
|
2380
|
+
case 'cs':
|
|
2381
|
+
return { valid: true, category: 'text', mime: 'text/x-csharp' };
|
|
2382
|
+
case 'css':
|
|
2383
|
+
return { valid: true, category: 'text', mime: 'text/css' };
|
|
2384
|
+
case 'doc':
|
|
2385
|
+
return { valid: true, category: 'document', mime: 'application/msword' };
|
|
2386
|
+
case 'docx':
|
|
2387
|
+
return { valid: true, category: 'document', mime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' };
|
|
2388
|
+
case 'go':
|
|
2389
|
+
return { valid: true, category: 'text', mime: 'text/x-golang' };
|
|
2390
|
+
case 'html':
|
|
2391
|
+
return { valid: true, category: 'text', mime: 'text/html' };
|
|
2392
|
+
case 'java':
|
|
2393
|
+
return { valid: true, category: 'text', mime: 'text/x-java' };
|
|
2394
|
+
case 'js':
|
|
2395
|
+
return { valid: true, category: 'text', mime: 'text/javascript' };
|
|
2396
|
+
case 'json':
|
|
2397
|
+
return { valid: true, category: 'text', mime: 'application/json' };
|
|
2398
|
+
case 'md':
|
|
2399
|
+
return { valid: true, category: 'text', mime: 'text/markdown' };
|
|
2400
|
+
case 'pdf':
|
|
2401
|
+
return { valid: true, category: 'document', mime: 'application/pdf' };
|
|
2402
|
+
case 'php':
|
|
2403
|
+
return { valid: true, category: 'text', mime: 'text/x-php' };
|
|
2404
|
+
case 'pptx':
|
|
2405
|
+
return { valid: true, category: 'document', mime: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' };
|
|
2406
|
+
case 'py':
|
|
2407
|
+
return { valid: true, category: 'text', mime: 'text/x-python' }; // or text/x-script.python
|
|
2408
|
+
case 'rb':
|
|
2409
|
+
return { valid: true, category: 'text', mime: 'text/x-ruby' };
|
|
2410
|
+
case 'sh':
|
|
2411
|
+
return { valid: true, category: 'text', mime: 'application/x-sh' };
|
|
2412
|
+
case 'tex':
|
|
2413
|
+
return { valid: true, category: 'text', mime: 'text/x-tex' };
|
|
2414
|
+
case 'ts':
|
|
2415
|
+
return { valid: true, category: 'text', mime: 'application/typescript' };
|
|
2416
|
+
case 'txt':
|
|
2417
|
+
return { valid: true, category: 'text', mime: 'text/plain' };
|
|
2418
|
+
|
|
2419
|
+
// ==============================
|
|
2420
|
+
// DEFAULT (INVALID)
|
|
2421
|
+
// ==============================
|
|
2422
|
+
default:
|
|
2423
|
+
return { valid: false, error: `Unsupported file extension: .${ext}` };
|
|
2424
|
+
}
|
|
2425
|
+
};
|