@muhgholy/next-drive 4.23.10 → 4.23.13

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.
@@ -1546,8 +1546,7 @@ var uploadChunkSchema = zod.z.object({
1546
1546
  fileName: nameSchema,
1547
1547
  fileSize: zod.z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
1548
1548
  fileType: zod.z.string().min(1).max(255),
1549
- folderId: zod.z.string().optional(),
1550
- unauthenticated: zod.z.coerce.boolean().optional()
1549
+ folderId: zod.z.string().optional()
1551
1550
  }).refine((data) => data.chunkIndex < data.totalChunks, {
1552
1551
  message: "Chunk index must be less than total chunks"
1553
1552
  });
@@ -2186,7 +2185,7 @@ var withSignedUrls = (items, config) => {
2186
2185
 
2187
2186
  // src/server/actions/drive.ts
2188
2187
  var handleDriveAction = async (ctx) => {
2189
- const { req, res, action, config, owner, isRootMode, information, provider, accountId } = ctx;
2188
+ const { req, res, action, config, owner, isRootMode, authenticated, information, provider, accountId } = ctx;
2190
2189
  switch (action) {
2191
2190
  case "list": {
2192
2191
  if (req.method !== "GET") return void res.status(405).json({ status: 405, message: "Listing files requires a GET request" });
@@ -2275,16 +2274,16 @@ var handleDriveAction = async (ctx) => {
2275
2274
  cleanupTempFiles(files);
2276
2275
  return void res.status(400).json({ status: 400, message: uploadData.error.errors[0].message });
2277
2276
  }
2278
- const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId, unauthenticated } = uploadData.data;
2277
+ const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId } = uploadData.data;
2279
2278
  let currentUploadId = driveId;
2280
2279
  const tempBaseDir = path__default.default.join(os2__default.default.tmpdir(), "next-drive-uploads");
2281
2280
  if (!currentUploadId) {
2282
2281
  if (chunkIndex !== 0) return void res.status(400).json({ message: "Could not upload: missing upload session for this chunk" });
2283
- if (unauthenticated) {
2282
+ if (!authenticated) {
2284
2283
  const unauth = config.security?.unauthenticated;
2285
2284
  if (!unauth?.enabled) {
2286
2285
  cleanupTempFiles(files);
2287
- return void res.status(403).json({ status: 403, message: "Anonymous uploads are not enabled" });
2286
+ return void res.status(401).json({ status: 401, message: "Authentication required to upload" });
2288
2287
  }
2289
2288
  if (fileSizeInBytes > unauth.maxUploadSizeInBytes) {
2290
2289
  cleanupTempFiles(files);
@@ -2343,15 +2342,15 @@ var handleDriveAction = async (ctx) => {
2343
2342
  const uploadDir2 = path__default.default.join(tempBaseDir, currentUploadId);
2344
2343
  fs__default.default.mkdirSync(uploadDir2, { recursive: true });
2345
2344
  const metadata = {
2346
- owner: unauthenticated ? null : owner,
2347
- accountId: unauthenticated ? null : accountId,
2345
+ owner: authenticated ? owner : null,
2346
+ accountId: authenticated ? accountId : null,
2348
2347
  providerName: provider.name,
2349
2348
  name: fileName,
2350
- parentId: unauthenticated || folderId === "root" || !folderId ? null : folderId,
2349
+ parentId: !authenticated || folderId === "root" || !folderId ? null : folderId,
2351
2350
  fileSize: fileSizeInBytes,
2352
2351
  mimeType: fileType,
2353
2352
  totalChunks,
2354
- unauthenticated: !!unauthenticated
2353
+ unauthenticated: !authenticated
2355
2354
  };
2356
2355
  fs__default.default.writeFileSync(path__default.default.join(uploadDir2, "metadata.json"), JSON.stringify(metadata));
2357
2356
  }
@@ -2689,12 +2688,12 @@ var driveAPIHandler = async (req, res) => {
2689
2688
  if (action === "information") {
2690
2689
  const { clientId, clientSecret, redirectUri } = config.storage?.google || {};
2691
2690
  const googleConfigured = !!(clientId && clientSecret && redirectUri);
2692
- let authenticated = false;
2691
+ let authenticated2 = false;
2693
2692
  try {
2694
2693
  await getDriveInformation({ method: "REQUEST", req });
2695
- authenticated = true;
2694
+ authenticated2 = true;
2696
2695
  } catch {
2697
- authenticated = false;
2696
+ authenticated2 = false;
2698
2697
  }
2699
2698
  res.status(200).json({
2700
2699
  status: 200,
@@ -2704,15 +2703,26 @@ var driveAPIHandler = async (req, res) => {
2704
2703
  google: googleConfigured
2705
2704
  },
2706
2705
  mode,
2707
- authenticated,
2706
+ authenticated: authenticated2,
2708
2707
  unauthenticatedUploads: !!config.security?.unauthenticated?.enabled
2709
2708
  }
2710
2709
  });
2711
2710
  return;
2712
2711
  }
2713
- const information = await getDriveInformation({ method: "REQUEST", req });
2714
- const { key: owner } = information;
2715
2712
  const isRootMode = mode === "ROOT";
2713
+ let information;
2714
+ let authenticated = true;
2715
+ try {
2716
+ information = await getDriveInformation({ method: "REQUEST", req });
2717
+ } catch (err) {
2718
+ if ((action === "upload" || action === "cancel") && config.security?.unauthenticated?.enabled) {
2719
+ information = { key: null, storage: { quotaInBytes: 0 } };
2720
+ authenticated = false;
2721
+ } else {
2722
+ throw err;
2723
+ }
2724
+ }
2725
+ const { key: owner } = information;
2716
2726
  const wasAuthHandled = await handleAuthAction(req, res, action, config, owner);
2717
2727
  if (wasAuthHandled) return;
2718
2728
  const { provider, accountId } = await resolveProvider(req, owner);
@@ -2723,6 +2733,7 @@ var driveAPIHandler = async (req, res) => {
2723
2733
  config,
2724
2734
  owner,
2725
2735
  isRootMode,
2736
+ authenticated,
2726
2737
  information,
2727
2738
  provider,
2728
2739
  accountId
@@ -2751,5 +2762,5 @@ exports.driveUpload = driveUpload;
2751
2762
  exports.drive_default = drive_default;
2752
2763
  exports.getDriveConfig = getDriveConfig;
2753
2764
  exports.getDriveInformation = getDriveInformation;
2754
- //# sourceMappingURL=chunk-V75PCJHT.cjs.map
2755
- //# sourceMappingURL=chunk-V75PCJHT.cjs.map
2765
+ //# sourceMappingURL=chunk-SDOFFTZ5.cjs.map
2766
+ //# sourceMappingURL=chunk-SDOFFTZ5.cjs.map