@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.
@@ -2173,7 +2173,7 @@ var withSignedUrls = (items, config) => {
2173
2173
 
2174
2174
  // src/server/actions/drive.ts
2175
2175
  var handleDriveAction = async (ctx) => {
2176
- const { req, res, action, config, owner, isRootMode, information, provider, accountId } = ctx;
2176
+ const { req, res, action, config, owner, isRootMode, authenticated, information, provider, accountId } = ctx;
2177
2177
  switch (action) {
2178
2178
  case "list": {
2179
2179
  if (req.method !== "GET") return void res.status(405).json({ status: 405, message: "Listing files requires a GET request" });
@@ -2312,6 +2312,10 @@ var handleDriveAction = async (ctx) => {
2312
2312
  store.concurrent++;
2313
2313
  }
2314
2314
  } else {
2315
+ if (!authenticated) {
2316
+ cleanupTempFiles(files);
2317
+ return void res.status(401).json({ status: 401, message: "Authentication required to upload" });
2318
+ }
2315
2319
  if (fileType && config.security) {
2316
2320
  if (!validateMimeType(fileType, config.security.allowedMimeTypes)) {
2317
2321
  cleanupTempFiles(files);
@@ -2676,12 +2680,12 @@ var driveAPIHandler = async (req, res) => {
2676
2680
  if (action === "information") {
2677
2681
  const { clientId, clientSecret, redirectUri } = config.storage?.google || {};
2678
2682
  const googleConfigured = !!(clientId && clientSecret && redirectUri);
2679
- let authenticated = false;
2683
+ let authenticated2 = false;
2680
2684
  try {
2681
2685
  await getDriveInformation({ method: "REQUEST", req });
2682
- authenticated = true;
2686
+ authenticated2 = true;
2683
2687
  } catch {
2684
- authenticated = false;
2688
+ authenticated2 = false;
2685
2689
  }
2686
2690
  res.status(200).json({
2687
2691
  status: 200,
@@ -2691,15 +2695,26 @@ var driveAPIHandler = async (req, res) => {
2691
2695
  google: googleConfigured
2692
2696
  },
2693
2697
  mode,
2694
- authenticated,
2698
+ authenticated: authenticated2,
2695
2699
  unauthenticatedUploads: !!config.security?.unauthenticated?.enabled
2696
2700
  }
2697
2701
  });
2698
2702
  return;
2699
2703
  }
2700
- const information = await getDriveInformation({ method: "REQUEST", req });
2701
- const { key: owner } = information;
2702
2704
  const isRootMode = mode === "ROOT";
2705
+ let information;
2706
+ let authenticated = true;
2707
+ try {
2708
+ information = await getDriveInformation({ method: "REQUEST", req });
2709
+ } catch (err) {
2710
+ if ((action === "upload" || action === "cancel") && config.security?.unauthenticated?.enabled) {
2711
+ information = { key: null, storage: { quotaInBytes: 0 } };
2712
+ authenticated = false;
2713
+ } else {
2714
+ throw err;
2715
+ }
2716
+ }
2717
+ const { key: owner } = information;
2703
2718
  const wasAuthHandled = await handleAuthAction(req, res, action, config, owner);
2704
2719
  if (wasAuthHandled) return;
2705
2720
  const { provider, accountId } = await resolveProvider(req, owner);
@@ -2710,6 +2725,7 @@ var driveAPIHandler = async (req, res) => {
2710
2725
  config,
2711
2726
  owner,
2712
2727
  isRootMode,
2728
+ authenticated,
2713
2729
  information,
2714
2730
  provider,
2715
2731
  accountId
@@ -2722,5 +2738,5 @@ var driveAPIHandler = async (req, res) => {
2722
2738
  };
2723
2739
 
2724
2740
  export { driveAPIHandler, driveCleanup, driveConfiguration, driveConfirm, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveListFiles, drivePurgeExpired, driveReadFile, driveUpload, drive_default, getDriveConfig, getDriveInformation };
2725
- //# sourceMappingURL=chunk-XUPDNN2U.js.map
2726
- //# sourceMappingURL=chunk-XUPDNN2U.js.map
2741
+ //# sourceMappingURL=chunk-26KZWPCF.js.map
2742
+ //# sourceMappingURL=chunk-26KZWPCF.js.map