@muhgholy/next-drive 4.23.31 → 4.23.33

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.
Files changed (41) hide show
  1. package/dist/{chunk-JEWYPKCM.js → chunk-2DCZENJ2.js} +116 -10
  2. package/dist/chunk-2DCZENJ2.js.map +1 -0
  3. package/dist/{chunk-FMJVTKXT.cjs → chunk-HWNIRA6Y.cjs} +39 -6
  4. package/dist/chunk-HWNIRA6Y.cjs.map +1 -0
  5. package/dist/{chunk-7XC5FDGZ.js → chunk-IWV6G7HQ.js} +39 -6
  6. package/dist/chunk-IWV6G7HQ.js.map +1 -0
  7. package/dist/{chunk-LN7U7XD7.cjs → chunk-WUG4ATLH.cjs} +150 -44
  8. package/dist/chunk-WUG4ATLH.cjs.map +1 -0
  9. package/dist/server/actions/public.d.ts.map +1 -1
  10. package/dist/server/config.d.ts.map +1 -1
  11. package/dist/server/express.cjs +12 -12
  12. package/dist/server/express.js +4 -4
  13. package/dist/server/hono.cjs +78 -13
  14. package/dist/server/hono.cjs.map +1 -1
  15. package/dist/server/hono.d.ts +1 -1
  16. package/dist/server/hono.d.ts.map +1 -1
  17. package/dist/server/hono.js +72 -7
  18. package/dist/server/hono.js.map +1 -1
  19. package/dist/server/index.cjs +19 -19
  20. package/dist/server/index.d.ts.map +1 -1
  21. package/dist/server/index.js +2 -2
  22. package/dist/server/storage-adapters/google.d.ts.map +1 -1
  23. package/dist/tus-5LLFMVQK.cjs +20 -0
  24. package/dist/tus-5LLFMVQK.cjs.map +1 -0
  25. package/dist/tus-C4T5ZDTG.js +3 -0
  26. package/dist/tus-C4T5ZDTG.js.map +1 -0
  27. package/dist/types/server/config.d.ts +8 -0
  28. package/dist/types/server/config.d.ts.map +1 -1
  29. package/dist/types/server/express.d.ts +3 -24
  30. package/dist/types/server/express.d.ts.map +1 -1
  31. package/dist/types/server/hono.d.ts +3 -24
  32. package/dist/types/server/hono.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-7XC5FDGZ.js.map +0 -1
  35. package/dist/chunk-FMJVTKXT.cjs.map +0 -1
  36. package/dist/chunk-JEWYPKCM.js.map +0 -1
  37. package/dist/chunk-LN7U7XD7.cjs.map +0 -1
  38. package/dist/tus-HCMP4OW7.js +0 -3
  39. package/dist/tus-HCMP4OW7.js.map +0 -1
  40. package/dist/tus-W4GOGQBV.cjs +0 -20
  41. package/dist/tus-W4GOGQBV.cjs.map +0 -1
@@ -251,7 +251,7 @@ var getGlobal = () => {
251
251
  config: null,
252
252
  migrationPromise: null,
253
253
  initialized: false,
254
- abuse: { ipHits: /* @__PURE__ */ new Map(), active: /* @__PURE__ */ new Map(), lastSweep: 0 }
254
+ abuse: { ipHits: /* @__PURE__ */ new Map(), active: /* @__PURE__ */ new Map(), lastSweep: 0, transformActive: 0 }
255
255
  };
256
256
  }
257
257
  return globalThis[GLOBAL_KEY];
@@ -281,6 +281,9 @@ var driveConfiguration = async (config) => {
281
281
  allowedMimeTypes: config.security?.allowedMimeTypes ?? ["*/*"],
282
282
  signedUrls: config.security?.signedUrls,
283
283
  trash: config.security?.trash,
284
+ publicRateLimit: config.security?.publicRateLimit,
285
+ transformConcurrency: config.security?.transformConcurrency,
286
+ cacheMaxAgeDays: config.security?.cacheMaxAgeDays,
284
287
  unauthenticated: config.security?.unauthenticated
285
288
  }
286
289
  };
@@ -300,11 +303,19 @@ var driveConfiguration = async (config) => {
300
303
  allowedMimeTypes: config.security?.allowedMimeTypes ?? ["*/*"],
301
304
  signedUrls: config.security?.signedUrls,
302
305
  trash: config.security?.trash,
306
+ publicRateLimit: config.security?.publicRateLimit,
307
+ transformConcurrency: config.security?.transformConcurrency,
308
+ cacheMaxAgeDays: config.security?.cacheMaxAgeDays,
303
309
  unauthenticated: config.security?.unauthenticated
304
310
  },
305
311
  information: config.information
306
312
  };
307
313
  }
314
+ if (!g.config.security?.signedUrls?.enabled && !g.config.security?.publicRateLimit) {
315
+ console.warn(
316
+ '[next-drive] security.signedUrls is disabled and security.publicRateLimit is unset - "?action=serve"/"thumbnail" will serve any valid file id to anyone, with no rate limit. Enable security.signedUrls (recommended) and/or set security.publicRateLimit if these files should not be fully public.'
317
+ );
318
+ }
308
319
  g.initialized = true;
309
320
  if (!g.migrationPromise) {
310
321
  g.migrationPromise = runMigrations(resolvedPath);
@@ -951,14 +962,36 @@ var GoogleDriveProvider = {
951
962
  }
952
963
  },
953
964
  openStream: async (item, accountId) => {
965
+ if (item.information.type === "FOLDER") throw new Error("Could not open Google Drive file: folders cannot be streamed");
966
+ const cachePath = path.join(getDriveConfig().storage.path, "file", item._id.toString(), "data.bin");
967
+ if (fs.existsSync(cachePath)) {
968
+ return {
969
+ stream: fs.createReadStream(cachePath),
970
+ mime: item.information.mime,
971
+ size: fs.statSync(cachePath).size
972
+ };
973
+ }
954
974
  const { client } = await createAuthClient(item.owner, accountId || item.storageAccountId?.toString());
955
975
  const drive = google.drive({ version: "v3", auth: client });
956
976
  if (!item.provider?.google?.id) throw new Error("Could not open Google Drive file: its Google file ID is missing");
957
- if (item.information.type === "FOLDER") throw new Error("Could not open Google Drive file: folders cannot be streamed");
958
977
  const res = await drive.files.get(
959
978
  { fileId: item.provider.google.id, alt: "media" },
960
979
  { responseType: "stream" }
961
980
  );
981
+ const fileDir = path.dirname(cachePath);
982
+ if (!fs.existsSync(fileDir)) fs.mkdirSync(fileDir, { recursive: true });
983
+ const tempPath = `${cachePath}.tmp`;
984
+ const writeStream = fs.createWriteStream(tempPath);
985
+ res.data.pipe(writeStream);
986
+ writeStream.on("finish", () => {
987
+ try {
988
+ fs.renameSync(tempPath, cachePath);
989
+ } catch {
990
+ fs.unlinkSync(tempPath);
991
+ }
992
+ });
993
+ writeStream.on("error", () => fs.unlink(tempPath, () => {
994
+ }));
962
995
  return {
963
996
  stream: res.data,
964
997
  mime: item.information.mime,
@@ -1706,7 +1739,7 @@ var driveCleanup = async () => {
1706
1739
  }
1707
1740
  }
1708
1741
  try {
1709
- const { getTusServer: getTusServer2 } = await import('./tus-HCMP4OW7.js');
1742
+ const { getTusServer: getTusServer2 } = await import('./tus-C4T5ZDTG.js');
1710
1743
  await getTusServer2().cleanUpExpiredUploads();
1711
1744
  } catch (e) {
1712
1745
  console.error("[next-drive] Failed to clean up expired tus uploads:", e);
@@ -1829,7 +1862,7 @@ var getTusServer = () => {
1829
1862
  }
1830
1863
  }
1831
1864
  const nreq = req.__nodeReq;
1832
- const ip = (nreq && abuse.clientId?.(nreq)) ?? (abuse.trustedHeaders ?? ["cf-connecting-ip", "x-forwarded-for"]).map((h) => req.headers.get(h)).find(Boolean)?.split(",")[0].trim() ?? nreq?.socket?.remoteAddress ?? "unknown";
1865
+ const ip = (nreq && abuse.clientId?.(nreq)) ?? (abuse.trustedHeaders ?? ["cf-connecting-ip", "x-real-ip", "x-forwarded-for"]).map((h) => req.headers.get(h)).find(Boolean)?.split(",")[0].trim() ?? nreq?.socket?.remoteAddress ?? "unknown";
1833
1866
  const hits = (store.ipHits.get(ip) ?? []).filter((t) => now - t < 36e5);
1834
1867
  const perIp = abuse.perIp;
1835
1868
  if (perIp && hits.filter((t) => now - t < perIp.windowMinutes * 6e4).length >= perIp.max) throw { status_code: 429, body: "Too many uploads, please try again later" };
@@ -1952,5 +1985,5 @@ var handleUpload = async (req, res, ctx) => {
1952
1985
  };
1953
1986
 
1954
1987
  export { GoogleDriveProvider, LocalStorageProvider, account_default, driveCleanup, driveConfiguration, driveConfirm, driveDelete, driveFilePath, driveGetUrl, driveInfo, driveList, driveListFiles, drivePurgeExpired, driveReadFile, driveUpload, drive_default, getDriveConfig, getDriveInformation, getImageSettings, getTusServer, handleUpload, resolveProvider, resolveTusCorsOptions, withSignedUrl, withSignedUrls };
1955
- //# sourceMappingURL=chunk-7XC5FDGZ.js.map
1956
- //# sourceMappingURL=chunk-7XC5FDGZ.js.map
1988
+ //# sourceMappingURL=chunk-IWV6G7HQ.js.map
1989
+ //# sourceMappingURL=chunk-IWV6G7HQ.js.map