@muhgholy/next-drive 4.23.25 → 4.23.26

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk45FZNILV_cjs = require('./chunk-45FZNILV.cjs');
3
+ var chunkDUTHZ5HA_cjs = require('./chunk-DUTHZ5HA.cjs');
4
4
  var path = require('path');
5
5
  var fs = require('fs');
6
6
  var crypto = require('crypto');
@@ -80,7 +80,7 @@ var handlePublicAction = async (req, res, action, config) => {
80
80
  res.status(400).json({ status: 400, message: "Could not open file: missing or invalid file ID" });
81
81
  return true;
82
82
  }
83
- const drive = await chunk45FZNILV_cjs.drive_default.findById(id);
83
+ const drive = await chunkDUTHZ5HA_cjs.drive_default.findById(id);
84
84
  if (!drive) {
85
85
  res.status(404).json({ status: 404, message: "File not found or no longer available" });
86
86
  return true;
@@ -109,7 +109,7 @@ var handlePublicAction = async (req, res, action, config) => {
109
109
  return true;
110
110
  }
111
111
  }
112
- const itemProvider = drive.provider?.type === "GOOGLE" ? chunk45FZNILV_cjs.GoogleDriveProvider : chunk45FZNILV_cjs.LocalStorageProvider;
112
+ const itemProvider = drive.provider?.type === "GOOGLE" ? chunkDUTHZ5HA_cjs.GoogleDriveProvider : chunkDUTHZ5HA_cjs.LocalStorageProvider;
113
113
  const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
114
114
  if (action === "thumbnail") {
115
115
  const stream2 = await itemProvider.getThumbnail(drive, itemAccountId);
@@ -136,7 +136,7 @@ var handlePublicAction = async (req, res, action, config) => {
136
136
  }
137
137
  if (shouldTransform) {
138
138
  try {
139
- const settings = chunk45FZNILV_cjs.getImageSettings(fileSize, quality, display, sizePreset, fit, position);
139
+ const settings = chunkDUTHZ5HA_cjs.getImageSettings(fileSize, quality, display, sizePreset, fit, position);
140
140
  let targetFormat = format || mime.split("/")[1];
141
141
  if (targetFormat === "jpg") targetFormat = "jpeg";
142
142
  if (!["jpeg", "png", "webp", "avif"].includes(targetFormat)) {
@@ -261,13 +261,13 @@ var handleAuthAction = async (req, res, action, config, owner) => {
261
261
  oAuth2Client.setCredentials(tokens);
262
262
  const oauth2 = googleapis.google.oauth2({ version: "v2", auth: oAuth2Client });
263
263
  const userInfo = await oauth2.userinfo.get();
264
- const existing = await chunk45FZNILV_cjs.account_default.findOne({ owner, "metadata.google.email": userInfo.data.email, "metadata.provider": "GOOGLE" });
264
+ const existing = await chunkDUTHZ5HA_cjs.account_default.findOne({ owner, "metadata.google.email": userInfo.data.email, "metadata.provider": "GOOGLE" });
265
265
  if (existing) {
266
266
  existing.metadata.google.credentials = tokens;
267
267
  existing.markModified("metadata");
268
268
  await existing.save();
269
269
  } else {
270
- const newAccount = new chunk45FZNILV_cjs.account_default({
270
+ const newAccount = new chunkDUTHZ5HA_cjs.account_default({
271
271
  owner,
272
272
  name: userInfo.data.name || "Google Drive",
273
273
  metadata: {
@@ -308,7 +308,7 @@ var handleAuthAction = async (req, res, action, config, owner) => {
308
308
  return true;
309
309
  }
310
310
  case "listAccounts": {
311
- const accounts = await chunk45FZNILV_cjs.account_default.find({ owner });
311
+ const accounts = await chunkDUTHZ5HA_cjs.account_default.find({ owner });
312
312
  res.status(200).json({
313
313
  status: 200,
314
314
  data: {
@@ -324,20 +324,20 @@ var handleAuthAction = async (req, res, action, config, owner) => {
324
324
  }
325
325
  case "removeAccount": {
326
326
  const { id } = req.query;
327
- const account = await chunk45FZNILV_cjs.account_default.findOne({ _id: id, owner });
327
+ const account = await chunkDUTHZ5HA_cjs.account_default.findOne({ _id: id, owner });
328
328
  if (!account) {
329
329
  res.status(404).json({ status: 404, message: "Could not disconnect: account not found" });
330
330
  return true;
331
331
  }
332
332
  if (account.metadata.provider === "GOOGLE") {
333
333
  try {
334
- await chunk45FZNILV_cjs.GoogleDriveProvider.revokeToken(owner, account._id.toString());
334
+ await chunkDUTHZ5HA_cjs.GoogleDriveProvider.revokeToken(owner, account._id.toString());
335
335
  } catch (e) {
336
336
  console.error("Failed to revoke Google token:", e);
337
337
  }
338
338
  }
339
- await chunk45FZNILV_cjs.account_default.deleteOne({ _id: id, owner });
340
- await chunk45FZNILV_cjs.drive_default.deleteMany({ owner, storageAccountId: id });
339
+ await chunkDUTHZ5HA_cjs.account_default.deleteOne({ _id: id, owner });
340
+ await chunkDUTHZ5HA_cjs.drive_default.deleteMany({ owner, storageAccountId: id });
341
341
  res.status(200).json({ status: 200, message: "Account removed" });
342
342
  return true;
343
343
  }
@@ -441,8 +441,8 @@ var handleDriveAction = async (ctx) => {
441
441
  query.owner = owner;
442
442
  }
443
443
  if (afterId) query._id = { $lt: afterId };
444
- const items = await chunk45FZNILV_cjs.drive_default.find(query, {}, { sort: { order: 1, _id: -1 }, limit });
445
- const plainItems = chunk45FZNILV_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
444
+ const items = await chunkDUTHZ5HA_cjs.drive_default.find(query, {}, { sort: { order: 1, _id: -1 }, limit });
445
+ const plainItems = chunkDUTHZ5HA_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
446
446
  res.status(200).json({ status: 200, message: "Items retrieved", data: { items: plainItems, hasMore: items.length === limit } });
447
447
  return;
448
448
  }
@@ -467,20 +467,20 @@ var handleDriveAction = async (ctx) => {
467
467
  query.owner = owner;
468
468
  }
469
469
  if (folderId && folderId !== "root") query.parentId = folderId;
470
- const items = await chunk45FZNILV_cjs.drive_default.find(query, {}, { limit, sort: { createdAt: -1 } });
471
- const plainItems = chunk45FZNILV_cjs.withSignedUrls(await Promise.all(items.map((i) => i.toClient())), config);
470
+ const items = await chunkDUTHZ5HA_cjs.drive_default.find(query, {}, { limit, sort: { createdAt: -1 } });
471
+ const plainItems = chunkDUTHZ5HA_cjs.withSignedUrls(await Promise.all(items.map((i) => i.toClient())), config);
472
472
  res.status(200).json({ status: 200, message: "Results", data: { items: plainItems } });
473
473
  return;
474
474
  }
475
475
  case "upload": {
476
- await chunk45FZNILV_cjs.handleUpload(req, res, { config, owner, authenticated, isRootMode, information, provider, accountId });
476
+ await chunkDUTHZ5HA_cjs.handleUpload(req, res, { config, owner, authenticated, isRootMode, information, provider, accountId });
477
477
  return;
478
478
  }
479
479
  case "createFolder": {
480
480
  const folderData = createFolderBodySchema.safeParse(req.body);
481
481
  if (!folderData.success) return void res.status(400).json({ status: 400, message: folderData.error.errors[0].message });
482
482
  const { name, parentId } = folderData.data;
483
- const item = chunk45FZNILV_cjs.withSignedUrl(await provider.createFolder(name, parentId ?? null, owner, accountId), config);
483
+ const item = chunkDUTHZ5HA_cjs.withSignedUrl(await provider.createFolder(name, parentId ?? null, owner, accountId), config);
484
484
  res.status(201).json({ status: 201, message: "Folder created", data: { item } });
485
485
  return;
486
486
  }
@@ -488,9 +488,9 @@ var handleDriveAction = async (ctx) => {
488
488
  const deleteData = deleteQuerySchema.safeParse(req.query);
489
489
  if (!deleteData.success) return void res.status(400).json({ status: 400, message: "Could not move to trash: invalid ID" });
490
490
  const { id } = deleteData.data;
491
- const drive = await chunk45FZNILV_cjs.drive_default.findById(id);
491
+ const drive = await chunkDUTHZ5HA_cjs.drive_default.findById(id);
492
492
  if (!drive) return void res.status(404).json({ status: 404, message: "Could not move to trash: item not found" });
493
- const itemProvider = drive.provider?.type === "GOOGLE" ? chunk45FZNILV_cjs.GoogleDriveProvider : chunk45FZNILV_cjs.LocalStorageProvider;
493
+ const itemProvider = drive.provider?.type === "GOOGLE" ? chunkDUTHZ5HA_cjs.GoogleDriveProvider : chunkDUTHZ5HA_cjs.LocalStorageProvider;
494
494
  const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
495
495
  try {
496
496
  await itemProvider.trash([id], owner, itemAccountId);
@@ -528,7 +528,7 @@ var handleDriveAction = async (ctx) => {
528
528
  }
529
529
  case "trash": {
530
530
  try {
531
- const { provider: trashProvider, accountId: trashAccountId } = await chunk45FZNILV_cjs.resolveProvider(req, owner);
531
+ const { provider: trashProvider, accountId: trashAccountId } = await chunkDUTHZ5HA_cjs.resolveProvider(req, owner);
532
532
  await trashProvider.syncTrash(owner, trashAccountId);
533
533
  } catch (e) {
534
534
  console.error("Trash sync failed", e);
@@ -539,8 +539,8 @@ var handleDriveAction = async (ctx) => {
539
539
  storageAccountId: accountId || null,
540
540
  trashedAt: { $ne: null }
541
541
  };
542
- const items = await chunk45FZNILV_cjs.drive_default.find(query, {}, { sort: { trashedAt: -1 } });
543
- const plainItems = chunk45FZNILV_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
542
+ const items = await chunkDUTHZ5HA_cjs.drive_default.find(query, {}, { sort: { trashedAt: -1 } });
543
+ const plainItems = chunkDUTHZ5HA_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
544
544
  res.status(200).json({ status: 200, message: "Trash items", data: { items: plainItems, hasMore: false } });
545
545
  return;
546
546
  }
@@ -548,16 +548,16 @@ var handleDriveAction = async (ctx) => {
548
548
  const restoreData = deleteQuerySchema.safeParse(req.query);
549
549
  if (!restoreData.success) return void res.status(400).json({ status: 400, message: "Could not restore: invalid ID" });
550
550
  const { id } = restoreData.data;
551
- const drive = await chunk45FZNILV_cjs.drive_default.findById(id);
551
+ const drive = await chunkDUTHZ5HA_cjs.drive_default.findById(id);
552
552
  if (!drive) return void res.status(404).json({ status: 404, message: "Could not restore: item not found" });
553
553
  let targetParentId = drive.parentId;
554
554
  if (targetParentId) {
555
- const parent = await chunk45FZNILV_cjs.drive_default.findById(targetParentId);
555
+ const parent = await chunkDUTHZ5HA_cjs.drive_default.findById(targetParentId);
556
556
  if (parent?.trashedAt) {
557
557
  targetParentId = null;
558
558
  }
559
559
  }
560
- const itemProvider = drive.provider?.type === "GOOGLE" ? chunk45FZNILV_cjs.GoogleDriveProvider : chunk45FZNILV_cjs.LocalStorageProvider;
560
+ const itemProvider = drive.provider?.type === "GOOGLE" ? chunkDUTHZ5HA_cjs.GoogleDriveProvider : chunkDUTHZ5HA_cjs.LocalStorageProvider;
561
561
  const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
562
562
  try {
563
563
  await itemProvider.untrash([id], owner, itemAccountId);
@@ -591,7 +591,7 @@ var handleDriveAction = async (ctx) => {
591
591
  console.error(`Failed to move item ${id}`, e);
592
592
  }
593
593
  }
594
- res.status(200).json({ status: 200, message: "Moved", data: { items: chunk45FZNILV_cjs.withSignedUrls(items, config) } });
594
+ res.status(200).json({ status: 200, message: "Moved", data: { items: chunkDUTHZ5HA_cjs.withSignedUrls(items, config) } });
595
595
  return;
596
596
  }
597
597
  case "reorder": {
@@ -612,7 +612,7 @@ var handleDriveAction = async (ctx) => {
612
612
  if (!isRootMode) {
613
613
  query.owner = owner;
614
614
  }
615
- const existingItems = await chunk45FZNILV_cjs.drive_default.find(query, { _id: 1, parentId: 1 });
615
+ const existingItems = await chunkDUTHZ5HA_cjs.drive_default.find(query, { _id: 1, parentId: 1 });
616
616
  if (existingItems.length !== ids.length) {
617
617
  return void res.status(404).json({ status: 404, message: "Could not reorder: one or more items were not found" });
618
618
  }
@@ -632,9 +632,9 @@ var handleDriveAction = async (ctx) => {
632
632
  update: { $set: { order } }
633
633
  }
634
634
  }));
635
- await chunk45FZNILV_cjs.drive_default.bulkWrite(operations);
636
- const updatedItems = await chunk45FZNILV_cjs.drive_default.find(query, {}, { sort: { order: 1 } });
637
- const plainItems = chunk45FZNILV_cjs.withSignedUrls(await Promise.all(updatedItems.map((item) => item.toClient())), config);
635
+ await chunkDUTHZ5HA_cjs.drive_default.bulkWrite(operations);
636
+ const updatedItems = await chunkDUTHZ5HA_cjs.drive_default.find(query, {}, { sort: { order: 1 } });
637
+ const plainItems = chunkDUTHZ5HA_cjs.withSignedUrls(await Promise.all(updatedItems.map((item) => item.toClient())), config);
638
638
  res.status(200).json({ status: 200, message: "Reordered", data: { items: plainItems } });
639
639
  return;
640
640
  }
@@ -642,7 +642,7 @@ var handleDriveAction = async (ctx) => {
642
642
  const renameData = renameBodySchema.safeParse({ id: req.query.id, ...req.body });
643
643
  if (!renameData.success) return void res.status(400).json({ status: 400, message: "Could not rename: invalid request data" });
644
644
  const { id, newName } = renameData.data;
645
- const item = chunk45FZNILV_cjs.withSignedUrl(await provider.rename(id, newName, owner, accountId), config);
645
+ const item = chunkDUTHZ5HA_cjs.withSignedUrl(await provider.rename(id, newName, owner, accountId), config);
646
646
  res.status(200).json({ status: 200, message: "Renamed", data: { item } });
647
647
  return;
648
648
  }
@@ -683,7 +683,7 @@ var driveAPIHandler = async (req, res) => {
683
683
  const action = req.query.action || (req.query.code && req.query.state ? "callback" : void 0);
684
684
  let config;
685
685
  try {
686
- config = chunk45FZNILV_cjs.getDriveConfig();
686
+ config = chunkDUTHZ5HA_cjs.getDriveConfig();
687
687
  } catch (error) {
688
688
  console.error("[next-drive] Configuration error:", error);
689
689
  res.status(500).json({ status: 500, message: "Drive is not ready: failed to initialize configuration" });
@@ -704,7 +704,7 @@ var driveAPIHandler = async (req, res) => {
704
704
  const googleConfigured = !!(clientId && clientSecret && redirectUri);
705
705
  let authenticated2 = false;
706
706
  try {
707
- await chunk45FZNILV_cjs.getDriveInformation({ method: "REQUEST", req });
707
+ await chunkDUTHZ5HA_cjs.getDriveInformation({ method: "REQUEST", req });
708
708
  authenticated2 = true;
709
709
  } catch {
710
710
  authenticated2 = false;
@@ -727,7 +727,7 @@ var driveAPIHandler = async (req, res) => {
727
727
  let information;
728
728
  let authenticated = true;
729
729
  try {
730
- information = await chunk45FZNILV_cjs.getDriveInformation({ method: "REQUEST", req });
730
+ information = await chunkDUTHZ5HA_cjs.getDriveInformation({ method: "REQUEST", req });
731
731
  } catch (err) {
732
732
  if (action === "upload" && config.security?.unauthenticated?.enabled) {
733
733
  information = { key: null, storage: { quotaInBytes: 0 } };
@@ -739,7 +739,7 @@ var driveAPIHandler = async (req, res) => {
739
739
  const { key: owner } = information;
740
740
  const wasAuthHandled = await handleAuthAction(req, res, action, config, owner);
741
741
  if (wasAuthHandled) return;
742
- const { provider, accountId } = await chunk45FZNILV_cjs.resolveProvider(req, owner);
742
+ const { provider, accountId } = await chunkDUTHZ5HA_cjs.resolveProvider(req, owner);
743
743
  await handleDriveAction({
744
744
  req,
745
745
  res,
@@ -761,5 +761,5 @@ var driveAPIHandler = async (req, res) => {
761
761
 
762
762
  exports.driveAPIHandler = driveAPIHandler;
763
763
  exports.driveFileSchemaZod = driveFileSchemaZod;
764
- //# sourceMappingURL=chunk-VTCBYFAK.cjs.map
765
- //# sourceMappingURL=chunk-VTCBYFAK.cjs.map
764
+ //# sourceMappingURL=chunk-PSJYCISB.cjs.map
765
+ //# sourceMappingURL=chunk-PSJYCISB.cjs.map