@muhgholy/next-drive 4.23.22 → 4.23.23
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.
- package/dist/{chunk-P5U4E6MG.js → chunk-CPMMHIQM.js} +46 -5
- package/dist/chunk-CPMMHIQM.js.map +1 -0
- package/dist/{chunk-SDOFFTZ5.cjs → chunk-IVSBLEMY.cjs} +46 -5
- package/dist/chunk-IVSBLEMY.cjs.map +1 -0
- package/dist/client/components/drive/upload.d.ts.map +1 -1
- package/dist/client/file-chooser.d.ts.map +1 -1
- package/dist/client/hooks/use-upload.d.ts +5 -2
- package/dist/client/hooks/use-upload.d.ts.map +1 -1
- package/dist/client/index.cjs +57 -14
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.css +1 -1
- package/dist/client/index.js +57 -14
- package/dist/client/index.js.map +1 -1
- package/dist/client/upload.d.ts.map +1 -1
- package/dist/server/actions/drive.d.ts.map +1 -1
- package/dist/server/express.cjs +11 -11
- package/dist/server/express.js +2 -2
- package/dist/server/hono.cjs +11 -11
- package/dist/server/hono.js +2 -2
- package/dist/server/index.cjs +18 -18
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/zod/schemas.d.ts +5 -0
- package/dist/server/zod/schemas.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +3 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-P5U4E6MG.js.map +0 -1
- 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-
|
|
2737
|
-
//# sourceMappingURL=chunk-
|
|
2777
|
+
//# sourceMappingURL=chunk-CPMMHIQM.js.map
|
|
2778
|
+
//# sourceMappingURL=chunk-CPMMHIQM.js.map
|