@muhgholy/next-drive 4.23.10 → 4.23.11

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.
@@ -2186,7 +2186,7 @@ var withSignedUrls = (items, config) => {
2186
2186
 
2187
2187
  // src/server/actions/drive.ts
2188
2188
  var handleDriveAction = async (ctx) => {
2189
- const { req, res, action, config, owner, isRootMode, information, provider, accountId } = ctx;
2189
+ const { req, res, action, config, owner, isRootMode, authenticated, information, provider, accountId } = ctx;
2190
2190
  switch (action) {
2191
2191
  case "list": {
2192
2192
  if (req.method !== "GET") return void res.status(405).json({ status: 405, message: "Listing files requires a GET request" });
@@ -2325,6 +2325,10 @@ var handleDriveAction = async (ctx) => {
2325
2325
  store.concurrent++;
2326
2326
  }
2327
2327
  } else {
2328
+ if (!authenticated) {
2329
+ cleanupTempFiles(files);
2330
+ return void res.status(401).json({ status: 401, message: "Authentication required to upload" });
2331
+ }
2328
2332
  if (fileType && config.security) {
2329
2333
  if (!validateMimeType(fileType, config.security.allowedMimeTypes)) {
2330
2334
  cleanupTempFiles(files);
@@ -2689,12 +2693,12 @@ var driveAPIHandler = async (req, res) => {
2689
2693
  if (action === "information") {
2690
2694
  const { clientId, clientSecret, redirectUri } = config.storage?.google || {};
2691
2695
  const googleConfigured = !!(clientId && clientSecret && redirectUri);
2692
- let authenticated = false;
2696
+ let authenticated2 = false;
2693
2697
  try {
2694
2698
  await getDriveInformation({ method: "REQUEST", req });
2695
- authenticated = true;
2699
+ authenticated2 = true;
2696
2700
  } catch {
2697
- authenticated = false;
2701
+ authenticated2 = false;
2698
2702
  }
2699
2703
  res.status(200).json({
2700
2704
  status: 200,
@@ -2704,15 +2708,26 @@ var driveAPIHandler = async (req, res) => {
2704
2708
  google: googleConfigured
2705
2709
  },
2706
2710
  mode,
2707
- authenticated,
2711
+ authenticated: authenticated2,
2708
2712
  unauthenticatedUploads: !!config.security?.unauthenticated?.enabled
2709
2713
  }
2710
2714
  });
2711
2715
  return;
2712
2716
  }
2713
- const information = await getDriveInformation({ method: "REQUEST", req });
2714
- const { key: owner } = information;
2715
2717
  const isRootMode = mode === "ROOT";
2718
+ let information;
2719
+ let authenticated = true;
2720
+ try {
2721
+ information = await getDriveInformation({ method: "REQUEST", req });
2722
+ } catch (err) {
2723
+ if ((action === "upload" || action === "cancel") && config.security?.unauthenticated?.enabled) {
2724
+ information = { key: null, storage: { quotaInBytes: 0 } };
2725
+ authenticated = false;
2726
+ } else {
2727
+ throw err;
2728
+ }
2729
+ }
2730
+ const { key: owner } = information;
2716
2731
  const wasAuthHandled = await handleAuthAction(req, res, action, config, owner);
2717
2732
  if (wasAuthHandled) return;
2718
2733
  const { provider, accountId } = await resolveProvider(req, owner);
@@ -2723,6 +2738,7 @@ var driveAPIHandler = async (req, res) => {
2723
2738
  config,
2724
2739
  owner,
2725
2740
  isRootMode,
2741
+ authenticated,
2726
2742
  information,
2727
2743
  provider,
2728
2744
  accountId
@@ -2751,5 +2767,5 @@ exports.driveUpload = driveUpload;
2751
2767
  exports.drive_default = drive_default;
2752
2768
  exports.getDriveConfig = getDriveConfig;
2753
2769
  exports.getDriveInformation = getDriveInformation;
2754
- //# sourceMappingURL=chunk-V75PCJHT.cjs.map
2755
- //# sourceMappingURL=chunk-V75PCJHT.cjs.map
2770
+ //# sourceMappingURL=chunk-NDHVF2IB.cjs.map
2771
+ //# sourceMappingURL=chunk-NDHVF2IB.cjs.map