@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.
- package/dist/{chunk-XUPDNN2U.js → chunk-P5U4E6MG.js} +29 -18
- package/dist/chunk-P5U4E6MG.js.map +1 -0
- package/dist/{chunk-V75PCJHT.cjs → chunk-SDOFFTZ5.cjs} +29 -18
- package/dist/chunk-SDOFFTZ5.cjs.map +1 -0
- package/dist/client/hooks/use-upload.d.ts +1 -1
- package/dist/client/hooks/use-upload.d.ts.map +1 -1
- package/dist/client/index.cjs +2 -3
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.js +2 -3
- package/dist/client/index.js.map +1 -1
- package/dist/server/actions/drive.d.ts +1 -0
- 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 +0 -5
- package/dist/server/zod/schemas.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-V75PCJHT.cjs.map +0 -1
- package/dist/chunk-XUPDNN2U.js.map +0 -1
|
@@ -1533,8 +1533,7 @@ 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()
|
|
1537
|
-
unauthenticated: z.coerce.boolean().optional()
|
|
1536
|
+
folderId: z.string().optional()
|
|
1538
1537
|
}).refine((data) => data.chunkIndex < data.totalChunks, {
|
|
1539
1538
|
message: "Chunk index must be less than total chunks"
|
|
1540
1539
|
});
|
|
@@ -2173,7 +2172,7 @@ var withSignedUrls = (items, config) => {
|
|
|
2173
2172
|
|
|
2174
2173
|
// src/server/actions/drive.ts
|
|
2175
2174
|
var handleDriveAction = async (ctx) => {
|
|
2176
|
-
const { req, res, action, config, owner, isRootMode, information, provider, accountId } = ctx;
|
|
2175
|
+
const { req, res, action, config, owner, isRootMode, authenticated, information, provider, accountId } = ctx;
|
|
2177
2176
|
switch (action) {
|
|
2178
2177
|
case "list": {
|
|
2179
2178
|
if (req.method !== "GET") return void res.status(405).json({ status: 405, message: "Listing files requires a GET request" });
|
|
@@ -2262,16 +2261,16 @@ var handleDriveAction = async (ctx) => {
|
|
|
2262
2261
|
cleanupTempFiles(files);
|
|
2263
2262
|
return void res.status(400).json({ status: 400, message: uploadData.error.errors[0].message });
|
|
2264
2263
|
}
|
|
2265
|
-
const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId
|
|
2264
|
+
const { chunkIndex, totalChunks, driveId, fileName, fileSize: fileSizeInBytes, fileType, folderId } = uploadData.data;
|
|
2266
2265
|
let currentUploadId = driveId;
|
|
2267
2266
|
const tempBaseDir = path.join(os2.tmpdir(), "next-drive-uploads");
|
|
2268
2267
|
if (!currentUploadId) {
|
|
2269
2268
|
if (chunkIndex !== 0) return void res.status(400).json({ message: "Could not upload: missing upload session for this chunk" });
|
|
2270
|
-
if (
|
|
2269
|
+
if (!authenticated) {
|
|
2271
2270
|
const unauth = config.security?.unauthenticated;
|
|
2272
2271
|
if (!unauth?.enabled) {
|
|
2273
2272
|
cleanupTempFiles(files);
|
|
2274
|
-
return void res.status(
|
|
2273
|
+
return void res.status(401).json({ status: 401, message: "Authentication required to upload" });
|
|
2275
2274
|
}
|
|
2276
2275
|
if (fileSizeInBytes > unauth.maxUploadSizeInBytes) {
|
|
2277
2276
|
cleanupTempFiles(files);
|
|
@@ -2330,15 +2329,15 @@ var handleDriveAction = async (ctx) => {
|
|
|
2330
2329
|
const uploadDir2 = path.join(tempBaseDir, currentUploadId);
|
|
2331
2330
|
fs.mkdirSync(uploadDir2, { recursive: true });
|
|
2332
2331
|
const metadata = {
|
|
2333
|
-
owner:
|
|
2334
|
-
accountId:
|
|
2332
|
+
owner: authenticated ? owner : null,
|
|
2333
|
+
accountId: authenticated ? accountId : null,
|
|
2335
2334
|
providerName: provider.name,
|
|
2336
2335
|
name: fileName,
|
|
2337
|
-
parentId:
|
|
2336
|
+
parentId: !authenticated || folderId === "root" || !folderId ? null : folderId,
|
|
2338
2337
|
fileSize: fileSizeInBytes,
|
|
2339
2338
|
mimeType: fileType,
|
|
2340
2339
|
totalChunks,
|
|
2341
|
-
unauthenticated:
|
|
2340
|
+
unauthenticated: !authenticated
|
|
2342
2341
|
};
|
|
2343
2342
|
fs.writeFileSync(path.join(uploadDir2, "metadata.json"), JSON.stringify(metadata));
|
|
2344
2343
|
}
|
|
@@ -2676,12 +2675,12 @@ var driveAPIHandler = async (req, res) => {
|
|
|
2676
2675
|
if (action === "information") {
|
|
2677
2676
|
const { clientId, clientSecret, redirectUri } = config.storage?.google || {};
|
|
2678
2677
|
const googleConfigured = !!(clientId && clientSecret && redirectUri);
|
|
2679
|
-
let
|
|
2678
|
+
let authenticated2 = false;
|
|
2680
2679
|
try {
|
|
2681
2680
|
await getDriveInformation({ method: "REQUEST", req });
|
|
2682
|
-
|
|
2681
|
+
authenticated2 = true;
|
|
2683
2682
|
} catch {
|
|
2684
|
-
|
|
2683
|
+
authenticated2 = false;
|
|
2685
2684
|
}
|
|
2686
2685
|
res.status(200).json({
|
|
2687
2686
|
status: 200,
|
|
@@ -2691,15 +2690,26 @@ var driveAPIHandler = async (req, res) => {
|
|
|
2691
2690
|
google: googleConfigured
|
|
2692
2691
|
},
|
|
2693
2692
|
mode,
|
|
2694
|
-
authenticated,
|
|
2693
|
+
authenticated: authenticated2,
|
|
2695
2694
|
unauthenticatedUploads: !!config.security?.unauthenticated?.enabled
|
|
2696
2695
|
}
|
|
2697
2696
|
});
|
|
2698
2697
|
return;
|
|
2699
2698
|
}
|
|
2700
|
-
const information = await getDriveInformation({ method: "REQUEST", req });
|
|
2701
|
-
const { key: owner } = information;
|
|
2702
2699
|
const isRootMode = mode === "ROOT";
|
|
2700
|
+
let information;
|
|
2701
|
+
let authenticated = true;
|
|
2702
|
+
try {
|
|
2703
|
+
information = await getDriveInformation({ method: "REQUEST", req });
|
|
2704
|
+
} catch (err) {
|
|
2705
|
+
if ((action === "upload" || action === "cancel") && config.security?.unauthenticated?.enabled) {
|
|
2706
|
+
information = { key: null, storage: { quotaInBytes: 0 } };
|
|
2707
|
+
authenticated = false;
|
|
2708
|
+
} else {
|
|
2709
|
+
throw err;
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
const { key: owner } = information;
|
|
2703
2713
|
const wasAuthHandled = await handleAuthAction(req, res, action, config, owner);
|
|
2704
2714
|
if (wasAuthHandled) return;
|
|
2705
2715
|
const { provider, accountId } = await resolveProvider(req, owner);
|
|
@@ -2710,6 +2720,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
2710
2720
|
config,
|
|
2711
2721
|
owner,
|
|
2712
2722
|
isRootMode,
|
|
2723
|
+
authenticated,
|
|
2713
2724
|
information,
|
|
2714
2725
|
provider,
|
|
2715
2726
|
accountId
|
|
@@ -2722,5 +2733,5 @@ var driveAPIHandler = async (req, res) => {
|
|
|
2722
2733
|
};
|
|
2723
2734
|
|
|
2724
2735
|
export { driveAPIHandler, driveCleanup, driveConfiguration, driveConfirm, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveListFiles, drivePurgeExpired, driveReadFile, driveUpload, drive_default, getDriveConfig, getDriveInformation };
|
|
2725
|
-
//# sourceMappingURL=chunk-
|
|
2726
|
-
//# sourceMappingURL=chunk-
|
|
2736
|
+
//# sourceMappingURL=chunk-P5U4E6MG.js.map
|
|
2737
|
+
//# sourceMappingURL=chunk-P5U4E6MG.js.map
|