@muhgholy/next-drive 4.17.1 → 4.19.0
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/README.md +23 -8
- package/dist/{chunk-QUBHH4G4.js → chunk-FWX344WM.js} +9 -8
- package/dist/chunk-FWX344WM.js.map +1 -0
- package/dist/{chunk-ZYDFFRK3.cjs → chunk-TBBX3C6E.cjs} +9 -8
- package/dist/chunk-TBBX3C6E.cjs.map +1 -0
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.css +1 -1
- package/dist/client/index.js +1 -1
- package/dist/server/config.d.ts +2 -3
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/controllers/drive.d.ts.map +1 -1
- package/dist/server/express.cjs +11 -11
- package/dist/server/express.js +2 -2
- package/dist/server/index.cjs +13 -13
- package/dist/server/index.js +1 -1
- package/dist/types/server/config.d.ts +9 -2
- package/dist/types/server/config.d.ts.map +1 -1
- package/dist/types/server/express.d.ts +1 -1
- package/dist/types/server/express.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-QUBHH4G4.js.map +0 -1
- package/dist/chunk-ZYDFFRK3.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -111,11 +111,20 @@ driveConfiguration({
|
|
|
111
111
|
expiresIn: 3600, // 1 hour
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
|
-
information: async (
|
|
115
|
-
|
|
116
|
-
if (
|
|
114
|
+
information: async (input): Promise<TDriveConfigInformation> => {
|
|
115
|
+
// REQUEST method — called from API handler with req
|
|
116
|
+
if (input.method === "REQUEST") {
|
|
117
|
+
const auth = await verifyAuth(input.req);
|
|
118
|
+
if (!auth) throw new Error("Unauthenticated");
|
|
119
|
+
return {
|
|
120
|
+
key: { userId: auth.userId },
|
|
121
|
+
storage: { quotaInBytes: 1024 * 1024 * 1024 }, // 1GB
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// KEY method — called from server-side code (driveUpload, etc.)
|
|
117
126
|
return {
|
|
118
|
-
key:
|
|
127
|
+
key: input.key,
|
|
119
128
|
storage: { quotaInBytes: 1024 * 1024 * 1024 }, // 1GB
|
|
120
129
|
};
|
|
121
130
|
},
|
|
@@ -198,11 +207,17 @@ driveConfigurationExpress({
|
|
|
198
207
|
maxUploadSizeInBytes: 50 * 1024 * 1024,
|
|
199
208
|
allowedMimeTypes: ["image/*", "video/*", "application/pdf"],
|
|
200
209
|
},
|
|
201
|
-
information: async (
|
|
202
|
-
|
|
203
|
-
|
|
210
|
+
information: async (input): Promise<TDriveConfigInformation> => {
|
|
211
|
+
if (input.method === "REQUEST") {
|
|
212
|
+
const auth = await verifyAuth(input.req);
|
|
213
|
+
if (!auth) throw new Error("Unauthenticated");
|
|
214
|
+
return {
|
|
215
|
+
key: { userId: auth.userId },
|
|
216
|
+
storage: { quotaInBytes: 1024 * 1024 * 1024 },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
204
219
|
return {
|
|
205
|
-
key:
|
|
220
|
+
key: input.key,
|
|
206
221
|
storage: { quotaInBytes: 1024 * 1024 * 1024 },
|
|
207
222
|
};
|
|
208
223
|
},
|
|
@@ -308,19 +308,19 @@ var getDriveConfig = () => {
|
|
|
308
308
|
if (!g.config) throw new Error("Drive configuration not initialized");
|
|
309
309
|
return g.config;
|
|
310
310
|
};
|
|
311
|
-
var getDriveInformation = async (
|
|
311
|
+
var getDriveInformation = async (input) => {
|
|
312
312
|
const config = getDriveConfig();
|
|
313
313
|
if (config.mode === "ROOT") {
|
|
314
314
|
if (!config.information) {
|
|
315
315
|
return {
|
|
316
|
-
key: null,
|
|
316
|
+
key: input.method === "KEY" ? input.key : null,
|
|
317
317
|
storage: { quotaInBytes: Number.MAX_SAFE_INTEGER }
|
|
318
318
|
// Unlimited quota in ROOT mode
|
|
319
319
|
};
|
|
320
320
|
}
|
|
321
|
-
return config.information(
|
|
321
|
+
return config.information(input);
|
|
322
322
|
}
|
|
323
|
-
return config.information(
|
|
323
|
+
return config.information(input);
|
|
324
324
|
};
|
|
325
325
|
var StorageAccountSchema = new Schema(
|
|
326
326
|
{
|
|
@@ -1607,7 +1607,8 @@ var driveUpload = async (source, key, options) => {
|
|
|
1607
1607
|
}
|
|
1608
1608
|
const isRootMode = config.mode === "ROOT";
|
|
1609
1609
|
if (!options.enforce && !isRootMode) {
|
|
1610
|
-
const
|
|
1610
|
+
const information = await getDriveInformation({ method: "KEY", key });
|
|
1611
|
+
const quota = await provider.getQuota(key, accountId, information.storage.quotaInBytes);
|
|
1611
1612
|
if (quota.usedInBytes + fileSize > quota.quotaInBytes) {
|
|
1612
1613
|
throw new Error("Storage quota exceeded");
|
|
1613
1614
|
}
|
|
@@ -1881,7 +1882,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
1881
1882
|
}
|
|
1882
1883
|
try {
|
|
1883
1884
|
const mode = config.mode || "NORMAL";
|
|
1884
|
-
const information = await getDriveInformation(req);
|
|
1885
|
+
const information = await getDriveInformation({ method: "REQUEST", req });
|
|
1885
1886
|
const { key: owner } = information;
|
|
1886
1887
|
const STORAGE_PATH = config.storage.path;
|
|
1887
1888
|
const isRootMode = mode === "ROOT";
|
|
@@ -2401,5 +2402,5 @@ var driveAPIHandler = async (req, res) => {
|
|
|
2401
2402
|
};
|
|
2402
2403
|
|
|
2403
2404
|
export { driveAPIHandler, driveConfiguration, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveReadFile, driveUpload, getDriveConfig, getDriveInformation };
|
|
2404
|
-
//# sourceMappingURL=chunk-
|
|
2405
|
-
//# sourceMappingURL=chunk-
|
|
2405
|
+
//# sourceMappingURL=chunk-FWX344WM.js.map
|
|
2406
|
+
//# sourceMappingURL=chunk-FWX344WM.js.map
|