@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.
@@ -251,21 +251,30 @@ var runMigrations = async (storagePath) => {
251
251
  };
252
252
 
253
253
  // src/server/config.ts
254
- var globalConfig = null;
255
- var migrationPromise = null;
256
- var configInitialized = false;
254
+ var GLOBAL_KEY = "__nextDrive";
255
+ var getGlobal = () => {
256
+ if (!globalThis[GLOBAL_KEY]) {
257
+ globalThis[GLOBAL_KEY] = {
258
+ config: null,
259
+ migrationPromise: null,
260
+ initialized: false
261
+ };
262
+ }
263
+ return globalThis[GLOBAL_KEY];
264
+ };
257
265
  var driveConfiguration = async (config) => {
266
+ const g = getGlobal();
258
267
  if (mongoose__default.default.connection.readyState !== 1) {
259
268
  throw new Error("Database not connected. Please connect to Mongoose before initializing next-drive.");
260
269
  }
261
- if (configInitialized && globalConfig) {
262
- if (migrationPromise) await migrationPromise;
263
- return globalConfig;
270
+ if (g.initialized && g.config) {
271
+ if (g.migrationPromise) await g.migrationPromise;
272
+ return g.config;
264
273
  }
265
274
  const resolvedPath = config.storage?.path || path__default.default.join(os3__default.default.tmpdir(), "next-drive-data");
266
275
  const mode = config.mode || "NORMAL";
267
276
  if (mode === "ROOT") {
268
- globalConfig = {
277
+ g.config = {
269
278
  ...config,
270
279
  mode: "ROOT",
271
280
  storage: {
@@ -284,7 +293,7 @@ var driveConfiguration = async (config) => {
284
293
  if (!config.information) {
285
294
  throw new Error("information callback is required in NORMAL mode");
286
295
  }
287
- globalConfig = {
296
+ g.config = {
288
297
  ...config,
289
298
  mode: "NORMAL",
290
299
  storage: {
@@ -300,16 +309,17 @@ var driveConfiguration = async (config) => {
300
309
  information: config.information
301
310
  };
302
311
  }
303
- configInitialized = true;
304
- if (!migrationPromise) {
305
- migrationPromise = runMigrations(resolvedPath);
312
+ g.initialized = true;
313
+ if (!g.migrationPromise) {
314
+ g.migrationPromise = runMigrations(resolvedPath);
306
315
  }
307
- await migrationPromise;
308
- return globalConfig;
316
+ await g.migrationPromise;
317
+ return g.config;
309
318
  };
310
319
  var getDriveConfig = () => {
311
- if (!globalConfig) throw new Error("Drive configuration not initialized");
312
- return globalConfig;
320
+ const g = getGlobal();
321
+ if (!g.config) throw new Error("Drive configuration not initialized");
322
+ return g.config;
313
323
  };
314
324
  var getDriveInformation = async (req) => {
315
325
  const config = getDriveConfig();
@@ -1610,7 +1620,7 @@ var driveUpload = async (source, key, options) => {
1610
1620
  }
1611
1621
  const isRootMode = config.mode === "ROOT";
1612
1622
  if (!options.enforce && !isRootMode) {
1613
- const quota = await provider.getQuota(key, accountId, void 0);
1623
+ const quota = await provider.getQuota(key, accountId, Number.MAX_SAFE_INTEGER);
1614
1624
  if (quota.usedInBytes + fileSize > quota.quotaInBytes) {
1615
1625
  throw new Error("Storage quota exceeded");
1616
1626
  }
@@ -2415,5 +2425,5 @@ exports.driveReadFile = driveReadFile;
2415
2425
  exports.driveUpload = driveUpload;
2416
2426
  exports.getDriveConfig = getDriveConfig;
2417
2427
  exports.getDriveInformation = getDriveInformation;
2418
- //# sourceMappingURL=chunk-HNLXZW5G.cjs.map
2419
- //# sourceMappingURL=chunk-HNLXZW5G.cjs.map
2428
+ //# sourceMappingURL=chunk-ZYDFFRK3.cjs.map
2429
+ //# sourceMappingURL=chunk-ZYDFFRK3.cjs.map