@muhgholy/next-drive 3.1.0 → 3.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../src/client/components/drive/upload.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAwC,MAAM,OAAO,CAAC;AA0E7D,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC,sBAgQD,CAAC"}
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../src/client/components/drive/upload.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAwC,MAAM,OAAO,CAAC;AA8G7D,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC,sBAoQD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useUpload.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/useUpload.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAYxD,eAAO,MAAM,SAAS,GAAI,aAAa,MAAM,EAAE,iBAAiB,MAAM,GAAG,IAAI,EAAE,kBAAiB,OAAe,EAAE,mBAAmB,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI;;yBAgKrG,IAAI,EAAE,YAAY,MAAM,GAAG,IAAI;uBAuB9D,MAAM;;CA+CxB,CAAC"}
1
+ {"version":3,"file":"useUpload.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/useUpload.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAYxD,eAAO,MAAM,SAAS,GAAI,aAAa,MAAM,EAAE,iBAAiB,MAAM,GAAG,IAAI,EAAE,kBAAiB,OAAe,EAAE,mBAAmB,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI;;yBAiKrG,IAAI,EAAE,YAAY,MAAM,GAAG,IAAI;uBAuB9D,MAAM;;CA+CxB,CAAC"}
@@ -304,8 +304,9 @@ var useUpload = (apiEndpoint, activeAccountId, withCredentials = false, onUpload
304
304
  try {
305
305
  const headers = {};
306
306
  if (activeAccountId) headers["x-drive-account"] = activeAccountId;
307
- addLog(uploadId, "info", `Sending chunk to ${apiEndpoint}?action=upload`);
308
- const response = await fetch(`${apiEndpoint}?action=upload`, {
307
+ const url = `${apiEndpoint.replace(/\/$/, "")}?action=upload`;
308
+ addLog(uploadId, "info", `Sending chunk to ${url}`);
309
+ const response = await fetch(url, {
309
310
  method: "POST",
310
311
  body: formData,
311
312
  headers,
@@ -440,7 +441,7 @@ var useUpload = (apiEndpoint, activeAccountId, withCredentials = false, onUpload
440
441
  }
441
442
  const upload = uploads.find((u) => u.id === id);
442
443
  if (upload?.driveId) {
443
- fetch(`${apiEndpoint}?action=cancel&id=${upload.driveId}`, {
444
+ fetch(`${apiEndpoint.replace(/\/$/, "")}?action=cancel&id=${upload.driveId}`, {
444
445
  method: "POST",
445
446
  credentials: withCredentials ? "include" : "same-origin"
446
447
  }).catch(() => {
@@ -2049,8 +2050,46 @@ var UploadStatusIcon = (props) => {
2049
2050
  var LogViewerDialog = (props) => {
2050
2051
  const { upload, open, onOpenChange } = props;
2051
2052
  const logs = upload.logs || [];
2053
+ const handleCopy = () => {
2054
+ const logText = logs.map((log) => `[${new Date(log.timestamp).toLocaleTimeString()}] ${log.type.toUpperCase()}: ${log.message}`).join("\n");
2055
+ navigator.clipboard.writeText(logText);
2056
+ };
2057
+ const handleDownload = () => {
2058
+ const logText = logs.map((log) => `[${new Date(log.timestamp).toLocaleTimeString()}] ${log.type.toUpperCase()}: ${log.message}`).join("\n");
2059
+ const blob = new Blob([logText], { type: "text/plain" });
2060
+ const url = URL.createObjectURL(blob);
2061
+ const a = document.createElement("a");
2062
+ a.href = url;
2063
+ a.download = `${upload.name}-logs.txt`;
2064
+ a.click();
2065
+ URL.revokeObjectURL(url);
2066
+ };
2052
2067
  return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-lg p-0 gap-0 max-h-[85vh] flex flex-col", children: [
2053
2068
  /* @__PURE__ */ jsx(DialogHeader, { className: "px-4 py-3 border-b", children: /* @__PURE__ */ jsx(DialogTitle, { className: "text-base truncate", children: upload.name }) }),
2069
+ /* @__PURE__ */ jsxs("div", { className: "sticky top-0 z-10 bg-background px-4 py-2 border-b flex items-center gap-2", children: [
2070
+ /* @__PURE__ */ jsx(
2071
+ Button,
2072
+ {
2073
+ type: "button",
2074
+ size: "sm",
2075
+ variant: "outline",
2076
+ onClick: handleCopy,
2077
+ disabled: logs.length === 0,
2078
+ children: "Copy"
2079
+ }
2080
+ ),
2081
+ /* @__PURE__ */ jsx(
2082
+ Button,
2083
+ {
2084
+ type: "button",
2085
+ size: "sm",
2086
+ variant: "outline",
2087
+ onClick: handleDownload,
2088
+ disabled: logs.length === 0,
2089
+ children: "Download"
2090
+ }
2091
+ )
2092
+ ] }),
2054
2093
  /* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-y-auto p-4 space-y-2", children: [
2055
2094
  logs.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground text-center py-8", children: "No logs available" }),
2056
2095
  logs.map((log, index) => /* @__PURE__ */ jsxs(
@@ -2087,6 +2126,8 @@ var DriveUpload = (props) => {
2087
2126
  const [isDragging, setIsDragging] = useState(false);
2088
2127
  const [showUploadsDialog, setShowUploadsDialog] = useState(false);
2089
2128
  const [logViewerUpload, setLogViewerUpload] = useState(null);
2129
+ const [manuallyOpened, setManuallyOpened] = useState(false);
2130
+ const hasAutoClosedRef = useRef(false);
2090
2131
  const inputRef = useRef(null);
2091
2132
  const { currentFolderId, setItems, apiEndpoint, activeAccountId, withCredentials, fetchItems, isLoading } = useDrive();
2092
2133
  const { uploads, uploadFiles, cancelUpload, cancelAllUploads } = useUpload(apiEndpoint, activeAccountId, withCredentials, (uploadedItem) => {
@@ -2096,17 +2137,18 @@ var DriveUpload = (props) => {
2096
2137
  onComplete?.(uploadedItem);
2097
2138
  });
2098
2139
  React3__default.useEffect(() => {
2099
- if (!showUploadsDialog || uploads.length === 0) return;
2140
+ if (!showUploadsDialog || uploads.length === 0 || manuallyOpened || hasAutoClosedRef.current) return;
2100
2141
  const allFinished = uploads.every(
2101
2142
  (u) => ["complete", "error", "cancelled"].includes(u.status)
2102
2143
  );
2103
2144
  if (allFinished) {
2104
2145
  const timer = setTimeout(() => {
2105
2146
  setShowUploadsDialog(false);
2147
+ hasAutoClosedRef.current = true;
2106
2148
  }, 2e3);
2107
2149
  return () => clearTimeout(timer);
2108
2150
  }
2109
- }, [uploads, showUploadsDialog]);
2151
+ }, [uploads, showUploadsDialog, manuallyOpened]);
2110
2152
  const filterFiles = useCallback((files) => {
2111
2153
  if (!accept) return files;
2112
2154
  return files.filter((file) => matchesMimeFilter(file.type, false, accept));
@@ -2116,6 +2158,7 @@ var DriveUpload = (props) => {
2116
2158
  const filteredFiles = filterFiles(Array.from(files));
2117
2159
  if (filteredFiles.length === 0) return;
2118
2160
  uploadFiles(filteredFiles, currentFolderId);
2161
+ setManuallyOpened(false);
2119
2162
  setShowUploadsDialog(true);
2120
2163
  }, [uploadFiles, currentFolderId, filterFiles]);
2121
2164
  const handleDrag = useCallback((e, dragging) => {
@@ -2262,7 +2305,10 @@ var DriveUpload = (props) => {
2262
2305
  type: "button",
2263
2306
  variant: "outline",
2264
2307
  size: "sm",
2265
- onClick: () => setShowUploadsDialog(true),
2308
+ onClick: () => {
2309
+ setManuallyOpened(true);
2310
+ setShowUploadsDialog(true);
2311
+ },
2266
2312
  children: [
2267
2313
  activeUploads.length > 0 ? /* @__PURE__ */ jsx(Loader2, { className: "!size-4 shrink-0 animate-spin" }) : /* @__PURE__ */ jsx(CheckCircle2, { className: "!size-4 shrink-0" }),
2268
2314
  /* @__PURE__ */ jsx("span", { children: activeUploads.length > 0 ? `(${activeUploads.length})` : "Status" })
@@ -2312,7 +2358,10 @@ var DriveUpload = (props) => {
2312
2358
  ]
2313
2359
  }
2314
2360
  ),
2315
- hasUploadsInProgress && /* @__PURE__ */ jsx("div", { className: "mt-4 text-center", children: /* @__PURE__ */ jsx(Button, { variant: "link", onClick: () => setShowUploadsDialog(true), children: "View Upload Progress" }) }),
2361
+ hasUploadsInProgress && /* @__PURE__ */ jsx("div", { className: "mt-4 text-center", children: /* @__PURE__ */ jsx(Button, { variant: "link", onClick: () => {
2362
+ setManuallyOpened(true);
2363
+ setShowUploadsDialog(true);
2364
+ }, children: "View Upload Progress" }) }),
2316
2365
  renderDialog(),
2317
2366
  logViewerUpload && /* @__PURE__ */ jsx(
2318
2367
  LogViewerDialog,