@muhgholy/next-drive 4.17.1 → 4.18.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 CHANGED
@@ -111,11 +111,20 @@ driveConfiguration({
111
111
  expiresIn: 3600, // 1 hour
112
112
  },
113
113
  },
114
- information: async (req): Promise<TDriveConfigInformation> => {
115
- const auth = await verifyAuth(req);
116
- if (!auth) throw new Error("Unauthenticated");
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: { userId: auth.userId },
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 (req): Promise<TDriveConfigInformation> => {
202
- const auth = await verifyAuth(req);
203
- if (!auth) throw new Error("Unauthenticated");
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: { userId: auth.userId },
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 (req) => {
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(req);
321
+ return config.information(input);
322
322
  }
323
- return config.information(req);
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 quota = await provider.getQuota(key, accountId, Number.MAX_SAFE_INTEGER);
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-QUBHH4G4.js.map
2405
- //# sourceMappingURL=chunk-QUBHH4G4.js.map
2405
+ //# sourceMappingURL=chunk-FWX344WM.js.map
2406
+ //# sourceMappingURL=chunk-FWX344WM.js.map