@muhgholy/next-drive 4.23.22 → 4.23.24

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.
Files changed (34) hide show
  1. package/dist/{chunk-P5U4E6MG.js → chunk-CPMMHIQM.js} +46 -5
  2. package/dist/chunk-CPMMHIQM.js.map +1 -0
  3. package/dist/{chunk-SDOFFTZ5.cjs → chunk-IVSBLEMY.cjs} +46 -5
  4. package/dist/chunk-IVSBLEMY.cjs.map +1 -0
  5. package/dist/client/components/drive/dnd/context.d.ts.map +1 -1
  6. package/dist/client/components/drive/explorer.d.ts.map +1 -1
  7. package/dist/client/components/drive/file-grid.d.ts.map +1 -1
  8. package/dist/client/components/drive/upload.d.ts.map +1 -1
  9. package/dist/client/file-chooser.d.ts.map +1 -1
  10. package/dist/client/hooks/use-marquee.d.ts +14 -0
  11. package/dist/client/hooks/use-marquee.d.ts.map +1 -0
  12. package/dist/client/hooks/use-upload.d.ts +5 -2
  13. package/dist/client/hooks/use-upload.d.ts.map +1 -1
  14. package/dist/client/index.cjs +156 -24
  15. package/dist/client/index.cjs.map +1 -1
  16. package/dist/client/index.css +1 -1
  17. package/dist/client/index.js +156 -24
  18. package/dist/client/index.js.map +1 -1
  19. package/dist/client/upload.d.ts.map +1 -1
  20. package/dist/server/actions/drive.d.ts.map +1 -1
  21. package/dist/server/express.cjs +11 -11
  22. package/dist/server/express.js +2 -2
  23. package/dist/server/hono.cjs +11 -11
  24. package/dist/server/hono.js +2 -2
  25. package/dist/server/index.cjs +18 -18
  26. package/dist/server/index.d.ts.map +1 -1
  27. package/dist/server/index.js +1 -1
  28. package/dist/server/zod/schemas.d.ts +5 -0
  29. package/dist/server/zod/schemas.d.ts.map +1 -1
  30. package/dist/types/client/index.d.ts +3 -1
  31. package/dist/types/client/index.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/chunk-P5U4E6MG.js.map +0 -1
  34. package/dist/chunk-SDOFFTZ5.cjs.map +0 -1
@@ -1546,7 +1546,8 @@ 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()
1549
+ folderId: zod.z.string().optional(),
1550
+ conflictAction: zod.z.enum(["rename", "replace"]).optional()
1550
1551
  }).refine((data) => data.chunkIndex < data.totalChunks, {
1551
1552
  message: "Chunk index must be less than total chunks"
1552
1553
  });
@@ -2268,13 +2269,14 @@ var handleDriveAction = async (ctx) => {
2268
2269
  fileName: getString(fields.fileName),
2269
2270
  fileSize: getInt(fields.fileSize),
2270
2271
  fileType: getString(fields.fileType),
2271
- folderId: getString(fields.folderId) || void 0
2272
+ folderId: getString(fields.folderId) || void 0,
2273
+ conflictAction: getString(fields.conflictAction) || void 0
2272
2274
  });
2273
2275
  if (!uploadData.success) {
2274
2276
  cleanupTempFiles(files);
2275
2277
  return void res.status(400).json({ status: 400, message: uploadData.error.errors[0].message });
2276
2278
  }
2277
- const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId } = uploadData.data;
2279
+ const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId, conflictAction } = uploadData.data;
2278
2280
  let currentUploadId = driveId;
2279
2281
  const tempBaseDir = path__default.default.join(os2__default.default.tmpdir(), "next-drive-uploads");
2280
2282
  if (!currentUploadId) {
@@ -2350,6 +2352,7 @@ var handleDriveAction = async (ctx) => {
2350
2352
  fileSize: fileSizeInBytes,
2351
2353
  mimeType: fileType,
2352
2354
  totalChunks,
2355
+ conflictAction: conflictAction ?? null,
2353
2356
  unauthenticated: !authenticated
2354
2357
  };
2355
2358
  fs__default.default.writeFileSync(path__default.default.join(uploadDir2, "metadata.json"), JSON.stringify(metadata));
@@ -2426,6 +2429,18 @@ var handleDriveAction = async (ctx) => {
2426
2429
  if (finalStats.size !== meta.fileSize) {
2427
2430
  throw new Error("Could not finish upload: the assembled file is incomplete (size mismatch)");
2428
2431
  }
2432
+ let replaceTargetId = null;
2433
+ if (meta.conflictAction === "replace") {
2434
+ const existing = await drive_default.findOne({ owner: meta.owner, storageAccountId: meta.accountId || null, "provider.type": meta.providerName, parentId: meta.parentId, name: meta.name, "information.type": "FILE", trashedAt: null });
2435
+ if (existing) replaceTargetId = String(existing._id);
2436
+ } else {
2437
+ const ext = path__default.default.extname(meta.name);
2438
+ const base = meta.name.slice(0, meta.name.length - ext.length);
2439
+ let n = 1;
2440
+ while (await drive_default.exists({ owner: meta.owner, storageAccountId: meta.accountId || null, "provider.type": meta.providerName, parentId: meta.parentId, name: meta.name, "information.type": "FILE", trashedAt: null })) {
2441
+ meta.name = `${base} (${n++})${ext}`;
2442
+ }
2443
+ }
2429
2444
  const drive = new drive_default({
2430
2445
  owner: meta.owner,
2431
2446
  storageAccountId: meta.accountId || null,
@@ -2445,6 +2460,7 @@ var handleDriveAction = async (ctx) => {
2445
2460
  await drive.save();
2446
2461
  try {
2447
2462
  const item = await provider.uploadFile(drive, finalTempPath, meta.accountId);
2463
+ if (replaceTargetId) await provider.delete([replaceTargetId], meta.owner, meta.accountId);
2448
2464
  fs__default.default.rmSync(uploadDir, { recursive: true, force: true });
2449
2465
  if (meta.unauthenticated) globalThis.__nextDrive.abuse.concurrent = Math.max(0, globalThis.__nextDrive.abuse.concurrent - 1);
2450
2466
  const newQuota = await provider.getQuota(meta.owner, meta.accountId, information.storage.quotaInBytes);
@@ -2665,7 +2681,32 @@ var handleDriveAction = async (ctx) => {
2665
2681
  };
2666
2682
 
2667
2683
  // src/server/index.ts
2684
+ var parseJsonBody = (req) => {
2685
+ return new Promise((resolve) => {
2686
+ try {
2687
+ const chunks = [];
2688
+ req.on("data", (chunk) => chunks.push(chunk));
2689
+ req.on("end", () => {
2690
+ const raw = Buffer.concat(chunks).toString();
2691
+ if (!raw) return resolve({});
2692
+ try {
2693
+ resolve(JSON.parse(raw));
2694
+ } catch {
2695
+ resolve({});
2696
+ }
2697
+ });
2698
+ req.on("error", () => resolve({}));
2699
+ } catch {
2700
+ resolve({});
2701
+ }
2702
+ });
2703
+ };
2668
2704
  var driveAPIHandler = async (req, res) => {
2705
+ if (req.body === void 0 && typeof req.on === "function" && (req.headers["content-type"] || "").includes("application/json")) {
2706
+ req.body = await parseJsonBody(req);
2707
+ } else if (req.body === void 0) {
2708
+ req.body = {};
2709
+ }
2669
2710
  const action = req.query.action || (req.query.code && req.query.state ? "callback" : void 0);
2670
2711
  let config;
2671
2712
  try {
@@ -2762,5 +2803,5 @@ exports.driveUpload = driveUpload;
2762
2803
  exports.drive_default = drive_default;
2763
2804
  exports.getDriveConfig = getDriveConfig;
2764
2805
  exports.getDriveInformation = getDriveInformation;
2765
- //# sourceMappingURL=chunk-SDOFFTZ5.cjs.map
2766
- //# sourceMappingURL=chunk-SDOFFTZ5.cjs.map
2806
+ //# sourceMappingURL=chunk-IVSBLEMY.cjs.map
2807
+ //# sourceMappingURL=chunk-IVSBLEMY.cjs.map