@muhgholy/next-drive 4.22.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.
@@ -1451,6 +1451,51 @@ var driveList = async (options) => {
1451
1451
  const items = await drive_default.find(query, {}, { sort: { order: 1, _id: -1 }, limit });
1452
1452
  return await Promise.all(items.map((item) => item.toClient()));
1453
1453
  };
1454
+ var driveListFiles = async (options) => {
1455
+ const { key, folderId, accountId } = options;
1456
+ const page = Math.max(1, options.page ?? 1);
1457
+ const limit = Math.min(Math.max(1, options.limit ?? 50), 100);
1458
+ let providerName = "LOCAL";
1459
+ if (accountId && accountId !== "LOCAL") {
1460
+ const account = await drive_default.db.model("StorageAccount").findOne({ _id: accountId, owner: key });
1461
+ if (!account) {
1462
+ throw new Error("Invalid Storage Account");
1463
+ }
1464
+ if (account.metadata.provider === "GOOGLE") {
1465
+ providerName = "GOOGLE";
1466
+ }
1467
+ }
1468
+ const query = {
1469
+ "provider.type": providerName,
1470
+ "information.type": "FILE",
1471
+ storageAccountId: accountId || null,
1472
+ trashedAt: null
1473
+ };
1474
+ if (key !== void 0) {
1475
+ query.owner = key;
1476
+ }
1477
+ if (folderId && folderId !== "root") {
1478
+ query.parentId = folderId;
1479
+ } else if (folderId === "root" || folderId === null) {
1480
+ query.parentId = null;
1481
+ }
1482
+ const skip = (page - 1) * limit;
1483
+ const [totalCount, items] = await Promise.all([
1484
+ drive_default.countDocuments(query),
1485
+ drive_default.find(query, {}, { sort: { createdAt: -1 }, skip, limit })
1486
+ ]);
1487
+ const totalPages = Math.ceil(totalCount / limit);
1488
+ return {
1489
+ items: await Promise.all(items.map((item) => item.toClient())),
1490
+ pagination: {
1491
+ page,
1492
+ limit,
1493
+ totalCount,
1494
+ totalPages,
1495
+ hasMore: page < totalPages
1496
+ }
1497
+ };
1498
+ };
1454
1499
  var driveDelete = async (source, options) => {
1455
1500
  const { recurse = true } = options || {};
1456
1501
  let drive;
@@ -2404,6 +2449,6 @@ var driveAPIHandler = async (req, res) => {
2404
2449
  }
2405
2450
  };
2406
2451
 
2407
- export { driveAPIHandler, driveConfiguration, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveReadFile, driveUpload, getDriveConfig, getDriveInformation };
2408
- //# sourceMappingURL=chunk-CR3QW3QN.js.map
2409
- //# sourceMappingURL=chunk-CR3QW3QN.js.map
2452
+ export { driveAPIHandler, driveConfiguration, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveListFiles, driveReadFile, driveUpload, drive_default, getDriveConfig, getDriveInformation };
2453
+ //# sourceMappingURL=chunk-MZFX6M44.js.map
2454
+ //# sourceMappingURL=chunk-MZFX6M44.js.map