@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
@@ -1533,7 +1533,8 @@ var uploadChunkSchema = z.object({
1533
1533
  fileName: nameSchema,
1534
1534
  fileSize: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
1535
1535
  fileType: z.string().min(1).max(255),
1536
- folderId: z.string().optional()
1536
+ folderId: z.string().optional(),
1537
+ conflictAction: z.enum(["rename", "replace"]).optional()
1537
1538
  }).refine((data) => data.chunkIndex < data.totalChunks, {
1538
1539
  message: "Chunk index must be less than total chunks"
1539
1540
  });
@@ -2255,13 +2256,14 @@ var handleDriveAction = async (ctx) => {
2255
2256
  fileName: getString(fields.fileName),
2256
2257
  fileSize: getInt(fields.fileSize),
2257
2258
  fileType: getString(fields.fileType),
2258
- folderId: getString(fields.folderId) || void 0
2259
+ folderId: getString(fields.folderId) || void 0,
2260
+ conflictAction: getString(fields.conflictAction) || void 0
2259
2261
  });
2260
2262
  if (!uploadData.success) {
2261
2263
  cleanupTempFiles(files);
2262
2264
  return void res.status(400).json({ status: 400, message: uploadData.error.errors[0].message });
2263
2265
  }
2264
- const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId } = uploadData.data;
2266
+ const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId, conflictAction } = uploadData.data;
2265
2267
  let currentUploadId = driveId;
2266
2268
  const tempBaseDir = path.join(os2.tmpdir(), "next-drive-uploads");
2267
2269
  if (!currentUploadId) {
@@ -2337,6 +2339,7 @@ var handleDriveAction = async (ctx) => {
2337
2339
  fileSize: fileSizeInBytes,
2338
2340
  mimeType: fileType,
2339
2341
  totalChunks,
2342
+ conflictAction: conflictAction ?? null,
2340
2343
  unauthenticated: !authenticated
2341
2344
  };
2342
2345
  fs.writeFileSync(path.join(uploadDir2, "metadata.json"), JSON.stringify(metadata));
@@ -2413,6 +2416,18 @@ var handleDriveAction = async (ctx) => {
2413
2416
  if (finalStats.size !== meta.fileSize) {
2414
2417
  throw new Error("Could not finish upload: the assembled file is incomplete (size mismatch)");
2415
2418
  }
2419
+ let replaceTargetId = null;
2420
+ if (meta.conflictAction === "replace") {
2421
+ 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 });
2422
+ if (existing) replaceTargetId = String(existing._id);
2423
+ } else {
2424
+ const ext = path.extname(meta.name);
2425
+ const base = meta.name.slice(0, meta.name.length - ext.length);
2426
+ let n = 1;
2427
+ 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 })) {
2428
+ meta.name = `${base} (${n++})${ext}`;
2429
+ }
2430
+ }
2416
2431
  const drive = new drive_default({
2417
2432
  owner: meta.owner,
2418
2433
  storageAccountId: meta.accountId || null,
@@ -2432,6 +2447,7 @@ var handleDriveAction = async (ctx) => {
2432
2447
  await drive.save();
2433
2448
  try {
2434
2449
  const item = await provider.uploadFile(drive, finalTempPath, meta.accountId);
2450
+ if (replaceTargetId) await provider.delete([replaceTargetId], meta.owner, meta.accountId);
2435
2451
  fs.rmSync(uploadDir, { recursive: true, force: true });
2436
2452
  if (meta.unauthenticated) globalThis.__nextDrive.abuse.concurrent = Math.max(0, globalThis.__nextDrive.abuse.concurrent - 1);
2437
2453
  const newQuota = await provider.getQuota(meta.owner, meta.accountId, information.storage.quotaInBytes);
@@ -2652,7 +2668,32 @@ var handleDriveAction = async (ctx) => {
2652
2668
  };
2653
2669
 
2654
2670
  // src/server/index.ts
2671
+ var parseJsonBody = (req) => {
2672
+ return new Promise((resolve) => {
2673
+ try {
2674
+ const chunks = [];
2675
+ req.on("data", (chunk) => chunks.push(chunk));
2676
+ req.on("end", () => {
2677
+ const raw = Buffer.concat(chunks).toString();
2678
+ if (!raw) return resolve({});
2679
+ try {
2680
+ resolve(JSON.parse(raw));
2681
+ } catch {
2682
+ resolve({});
2683
+ }
2684
+ });
2685
+ req.on("error", () => resolve({}));
2686
+ } catch {
2687
+ resolve({});
2688
+ }
2689
+ });
2690
+ };
2655
2691
  var driveAPIHandler = async (req, res) => {
2692
+ if (req.body === void 0 && typeof req.on === "function" && (req.headers["content-type"] || "").includes("application/json")) {
2693
+ req.body = await parseJsonBody(req);
2694
+ } else if (req.body === void 0) {
2695
+ req.body = {};
2696
+ }
2656
2697
  const action = req.query.action || (req.query.code && req.query.state ? "callback" : void 0);
2657
2698
  let config;
2658
2699
  try {
@@ -2733,5 +2774,5 @@ var driveAPIHandler = async (req, res) => {
2733
2774
  };
2734
2775
 
2735
2776
  export { driveAPIHandler, driveCleanup, driveConfiguration, driveConfirm, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveListFiles, drivePurgeExpired, driveReadFile, driveUpload, drive_default, getDriveConfig, getDriveInformation };
2736
- //# sourceMappingURL=chunk-P5U4E6MG.js.map
2737
- //# sourceMappingURL=chunk-P5U4E6MG.js.map
2777
+ //# sourceMappingURL=chunk-CPMMHIQM.js.map
2778
+ //# sourceMappingURL=chunk-CPMMHIQM.js.map