@muhgholy/next-drive 4.16.0 → 4.17.1

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.
@@ -238,21 +238,30 @@ var runMigrations = async (storagePath) => {
238
238
  };
239
239
 
240
240
  // src/server/config.ts
241
- var globalConfig = null;
242
- var migrationPromise = null;
243
- var configInitialized = false;
241
+ var GLOBAL_KEY = "__nextDrive";
242
+ var getGlobal = () => {
243
+ if (!globalThis[GLOBAL_KEY]) {
244
+ globalThis[GLOBAL_KEY] = {
245
+ config: null,
246
+ migrationPromise: null,
247
+ initialized: false
248
+ };
249
+ }
250
+ return globalThis[GLOBAL_KEY];
251
+ };
244
252
  var driveConfiguration = async (config) => {
253
+ const g = getGlobal();
245
254
  if (mongoose.connection.readyState !== 1) {
246
255
  throw new Error("Database not connected. Please connect to Mongoose before initializing next-drive.");
247
256
  }
248
- if (configInitialized && globalConfig) {
249
- if (migrationPromise) await migrationPromise;
250
- return globalConfig;
257
+ if (g.initialized && g.config) {
258
+ if (g.migrationPromise) await g.migrationPromise;
259
+ return g.config;
251
260
  }
252
261
  const resolvedPath = config.storage?.path || path.join(os3.tmpdir(), "next-drive-data");
253
262
  const mode = config.mode || "NORMAL";
254
263
  if (mode === "ROOT") {
255
- globalConfig = {
264
+ g.config = {
256
265
  ...config,
257
266
  mode: "ROOT",
258
267
  storage: {
@@ -271,7 +280,7 @@ var driveConfiguration = async (config) => {
271
280
  if (!config.information) {
272
281
  throw new Error("information callback is required in NORMAL mode");
273
282
  }
274
- globalConfig = {
283
+ g.config = {
275
284
  ...config,
276
285
  mode: "NORMAL",
277
286
  storage: {
@@ -287,16 +296,17 @@ var driveConfiguration = async (config) => {
287
296
  information: config.information
288
297
  };
289
298
  }
290
- configInitialized = true;
291
- if (!migrationPromise) {
292
- migrationPromise = runMigrations(resolvedPath);
299
+ g.initialized = true;
300
+ if (!g.migrationPromise) {
301
+ g.migrationPromise = runMigrations(resolvedPath);
293
302
  }
294
- await migrationPromise;
295
- return globalConfig;
303
+ await g.migrationPromise;
304
+ return g.config;
296
305
  };
297
306
  var getDriveConfig = () => {
298
- if (!globalConfig) throw new Error("Drive configuration not initialized");
299
- return globalConfig;
307
+ const g = getGlobal();
308
+ if (!g.config) throw new Error("Drive configuration not initialized");
309
+ return g.config;
300
310
  };
301
311
  var getDriveInformation = async (req) => {
302
312
  const config = getDriveConfig();
@@ -1597,7 +1607,7 @@ var driveUpload = async (source, key, options) => {
1597
1607
  }
1598
1608
  const isRootMode = config.mode === "ROOT";
1599
1609
  if (!options.enforce && !isRootMode) {
1600
- const quota = await provider.getQuota(key, accountId, void 0);
1610
+ const quota = await provider.getQuota(key, accountId, Number.MAX_SAFE_INTEGER);
1601
1611
  if (quota.usedInBytes + fileSize > quota.quotaInBytes) {
1602
1612
  throw new Error("Storage quota exceeded");
1603
1613
  }
@@ -2391,5 +2401,5 @@ var driveAPIHandler = async (req, res) => {
2391
2401
  };
2392
2402
 
2393
2403
  export { driveAPIHandler, driveConfiguration, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveReadFile, driveUpload, getDriveConfig, getDriveInformation };
2394
- //# sourceMappingURL=chunk-PFIAZK57.js.map
2395
- //# sourceMappingURL=chunk-PFIAZK57.js.map
2404
+ //# sourceMappingURL=chunk-QUBHH4G4.js.map
2405
+ //# sourceMappingURL=chunk-QUBHH4G4.js.map