@muhgholy/next-drive 4.23.0 → 4.23.1

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/README.md CHANGED
@@ -461,6 +461,66 @@ const items = await driveList({
461
461
  | `limit` | `number` | No | Maximum items to return (default: 100) |
462
462
  | `afterId` | `string` | No | Last item ID for pagination |
463
463
 
464
+ ### List Files (Paginated)
465
+
466
+ List **files only** (not folders) with offset-based pagination:
467
+
468
+ ```typescript
469
+ import { driveListFiles } from "@muhgholy/next-drive/server";
470
+
471
+ // List all files (page 1, default limit 50)
472
+ const result = await driveListFiles({});
473
+
474
+ // List files for a specific owner
475
+ const result = await driveListFiles({ key: { userId: "123" } });
476
+
477
+ // List files in a folder with pagination
478
+ const result = await driveListFiles({
479
+ key: { userId: "123" },
480
+ folderId: "folderIdHere",
481
+ page: 2,
482
+ limit: 20,
483
+ });
484
+
485
+ // Access pagination info
486
+ console.log(result.pagination);
487
+ // { page: 2, limit: 20, totalCount: 87, totalPages: 5, hasMore: true }
488
+ ```
489
+
490
+ **Options:**
491
+
492
+ | Option | Type | Required | Description |
493
+ | ----------- | -------------------------- | -------- | ---------------------------------------------- |
494
+ | `key` | `Record<string, unknown>` | No | Owner key (omit to list all files) |
495
+ | `folderId` | `string \| null` | No | Folder ID (null/'root' for root, omit for all) |
496
+ | `accountId` | `string` | No | Storage account ID |
497
+ | `page` | `number` | No | Page number (default: 1) |
498
+ | `limit` | `number` | No | Items per page (default: 50, max: 100) |
499
+
500
+ **Returns:** `{ items: TDatabaseDrive[], pagination: { page, limit, totalCount, totalPages, hasMore } }`
501
+
502
+ ### Direct Database Access
503
+
504
+ For custom queries, use the exposed Mongoose model:
505
+
506
+ ```typescript
507
+ import { DatabaseMongoDrive } from "@muhgholy/next-drive/server";
508
+ import type { IDatabaseDriveDocument } from "@muhgholy/next-drive/server";
509
+
510
+ // Custom query
511
+ const files = await DatabaseMongoDrive.find({
512
+ owner: { userId: "123" },
513
+ "information.type": "FILE",
514
+ "information.mime": { $regex: "^image/" },
515
+ });
516
+
517
+ // Aggregation
518
+ const stats = await DatabaseMongoDrive.aggregate([
519
+ { $match: { owner: { userId: "123" }, trashedAt: null } },
520
+ { $group: { _id: "$information.type", count: { $sum: 1 } } },
521
+ ]);
522
+ ```
523
+
464
524
  ### Delete File or Folder
465
525
 
466
526
  Permanently delete a file or folder from the drive system:
@@ -1464,6 +1464,51 @@ var driveList = async (options) => {
1464
1464
  const items = await drive_default.find(query, {}, { sort: { order: 1, _id: -1 }, limit });
1465
1465
  return await Promise.all(items.map((item) => item.toClient()));
1466
1466
  };
1467
+ var driveListFiles = async (options) => {
1468
+ const { key, folderId, accountId } = options;
1469
+ const page = Math.max(1, options.page ?? 1);
1470
+ const limit = Math.min(Math.max(1, options.limit ?? 50), 100);
1471
+ let providerName = "LOCAL";
1472
+ if (accountId && accountId !== "LOCAL") {
1473
+ const account = await drive_default.db.model("StorageAccount").findOne({ _id: accountId, owner: key });
1474
+ if (!account) {
1475
+ throw new Error("Invalid Storage Account");
1476
+ }
1477
+ if (account.metadata.provider === "GOOGLE") {
1478
+ providerName = "GOOGLE";
1479
+ }
1480
+ }
1481
+ const query = {
1482
+ "provider.type": providerName,
1483
+ "information.type": "FILE",
1484
+ storageAccountId: accountId || null,
1485
+ trashedAt: null
1486
+ };
1487
+ if (key !== void 0) {
1488
+ query.owner = key;
1489
+ }
1490
+ if (folderId && folderId !== "root") {
1491
+ query.parentId = folderId;
1492
+ } else if (folderId === "root" || folderId === null) {
1493
+ query.parentId = null;
1494
+ }
1495
+ const skip = (page - 1) * limit;
1496
+ const [totalCount, items] = await Promise.all([
1497
+ drive_default.countDocuments(query),
1498
+ drive_default.find(query, {}, { sort: { createdAt: -1 }, skip, limit })
1499
+ ]);
1500
+ const totalPages = Math.ceil(totalCount / limit);
1501
+ return {
1502
+ items: await Promise.all(items.map((item) => item.toClient())),
1503
+ pagination: {
1504
+ page,
1505
+ limit,
1506
+ totalCount,
1507
+ totalPages,
1508
+ hasMore: page < totalPages
1509
+ }
1510
+ };
1511
+ };
1467
1512
  var driveDelete = async (source, options) => {
1468
1513
  const { recurse = true } = options || {};
1469
1514
  let drive;
@@ -2425,9 +2470,11 @@ exports.driveFileSchemaZod = driveFileSchemaZod;
2425
2470
  exports.driveGetUrl = driveGetUrl;
2426
2471
  exports.driveInfo = driveInfo;
2427
2472
  exports.driveList = driveList;
2473
+ exports.driveListFiles = driveListFiles;
2428
2474
  exports.driveReadFile = driveReadFile;
2429
2475
  exports.driveUpload = driveUpload;
2476
+ exports.drive_default = drive_default;
2430
2477
  exports.getDriveConfig = getDriveConfig;
2431
2478
  exports.getDriveInformation = getDriveInformation;
2432
- //# sourceMappingURL=chunk-EUAHSB2J.cjs.map
2433
- //# sourceMappingURL=chunk-EUAHSB2J.cjs.map
2479
+ //# sourceMappingURL=chunk-BGCV4Y2V.cjs.map
2480
+ //# sourceMappingURL=chunk-BGCV4Y2V.cjs.map