markpdfdown 0.4.1 → 0.4.2-beta.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.
|
@@ -125843,6 +125843,7 @@ const Preview = () => {
|
|
|
125843
125843
|
) });
|
|
125844
125844
|
};
|
|
125845
125845
|
const { Text } = Typography;
|
|
125846
|
+
const dedupeAndSortPages = (pageItems) => Array.from(new Map(pageItems.map((page) => [page.page, page])).values()).sort((a2, b) => a2.page - b.page);
|
|
125846
125847
|
const CloudPreview = () => {
|
|
125847
125848
|
const { id } = useParams();
|
|
125848
125849
|
const navigate = useNavigate();
|
|
@@ -125860,6 +125861,9 @@ const CloudPreview = () => {
|
|
|
125860
125861
|
const [imageUrl, setImageUrl] = reactExports.useState(null);
|
|
125861
125862
|
const [imageError, setImageError] = reactExports.useState(false);
|
|
125862
125863
|
const [imageLoading, setImageLoading] = reactExports.useState(false);
|
|
125864
|
+
const taskPagesPageSizeRef = reactExports.useRef(100);
|
|
125865
|
+
const attemptedFallbackPagesRef = reactExports.useRef(/* @__PURE__ */ new Set());
|
|
125866
|
+
const inFlightFallbackPagesRef = reactExports.useRef(/* @__PURE__ */ new Set());
|
|
125863
125867
|
const currentPageData = pages.find((p2) => p2.page === currentPage);
|
|
125864
125868
|
const fetchTask = reactExports.useCallback(async () => {
|
|
125865
125869
|
if (!id || !cloudContext) return;
|
|
@@ -125878,11 +125882,29 @@ const CloudPreview = () => {
|
|
|
125878
125882
|
}, [id, cloudContext, message2, navigate, t2]);
|
|
125879
125883
|
const fetchPages = reactExports.useCallback(async () => {
|
|
125880
125884
|
if (!id || !cloudContext) return;
|
|
125885
|
+
attemptedFallbackPagesRef.current.clear();
|
|
125886
|
+
inFlightFallbackPagesRef.current.clear();
|
|
125887
|
+
taskPagesPageSizeRef.current = 100;
|
|
125881
125888
|
setLoading(true);
|
|
125882
125889
|
try {
|
|
125883
|
-
const
|
|
125884
|
-
|
|
125885
|
-
|
|
125890
|
+
const requestedPageSize = 100;
|
|
125891
|
+
const result = await cloudContext.getTaskPages(id, 1, requestedPageSize);
|
|
125892
|
+
if (result.success) {
|
|
125893
|
+
const effectivePageSize = Math.max(1, result.pagination?.page_size || requestedPageSize);
|
|
125894
|
+
taskPagesPageSizeRef.current = effectivePageSize;
|
|
125895
|
+
const allPages = [...result.data || []];
|
|
125896
|
+
const totalApiPages = Math.max(1, result.pagination?.total_pages || 1);
|
|
125897
|
+
for (let apiPage = 2; apiPage <= totalApiPages; apiPage++) {
|
|
125898
|
+
try {
|
|
125899
|
+
const nextPageResult = await cloudContext.getTaskPages(id, apiPage, effectivePageSize);
|
|
125900
|
+
if (nextPageResult.success && nextPageResult.data?.length) {
|
|
125901
|
+
allPages.push(...nextPageResult.data);
|
|
125902
|
+
}
|
|
125903
|
+
} catch {
|
|
125904
|
+
console.error(`Failed to fetch page chunk ${apiPage}`);
|
|
125905
|
+
}
|
|
125906
|
+
}
|
|
125907
|
+
setPages(dedupeAndSortPages(allPages));
|
|
125886
125908
|
}
|
|
125887
125909
|
} catch {
|
|
125888
125910
|
console.error("Failed to fetch pages");
|
|
@@ -125890,6 +125912,50 @@ const CloudPreview = () => {
|
|
|
125890
125912
|
setLoading(false);
|
|
125891
125913
|
}
|
|
125892
125914
|
}, [id, cloudContext]);
|
|
125915
|
+
const ensureCurrentPageLoaded = reactExports.useCallback(async () => {
|
|
125916
|
+
if (!id || !cloudContext || loading) return;
|
|
125917
|
+
if (pages.some((page) => page.page === currentPage)) return;
|
|
125918
|
+
if (attemptedFallbackPagesRef.current.has(currentPage) || inFlightFallbackPagesRef.current.has(currentPage)) return;
|
|
125919
|
+
const targetPage = currentPage;
|
|
125920
|
+
let shouldMarkAttempted = true;
|
|
125921
|
+
let effectivePageSize = Math.max(1, taskPagesPageSizeRef.current || 1);
|
|
125922
|
+
let fallbackApiPage = Math.max(1, Math.floor((targetPage - 1) / effectivePageSize) + 1);
|
|
125923
|
+
inFlightFallbackPagesRef.current.add(targetPage);
|
|
125924
|
+
try {
|
|
125925
|
+
let result = await cloudContext.getTaskPages(id, fallbackApiPage, effectivePageSize);
|
|
125926
|
+
const responsePageSize = result.pagination?.page_size ? Math.max(1, result.pagination.page_size) : void 0;
|
|
125927
|
+
if (responsePageSize) {
|
|
125928
|
+
taskPagesPageSizeRef.current = responsePageSize;
|
|
125929
|
+
if (responsePageSize !== effectivePageSize) {
|
|
125930
|
+
effectivePageSize = responsePageSize;
|
|
125931
|
+
const correctedApiPage = Math.max(1, Math.floor((targetPage - 1) / effectivePageSize) + 1);
|
|
125932
|
+
if (correctedApiPage !== fallbackApiPage) {
|
|
125933
|
+
fallbackApiPage = correctedApiPage;
|
|
125934
|
+
result = await cloudContext.getTaskPages(id, fallbackApiPage, effectivePageSize);
|
|
125935
|
+
}
|
|
125936
|
+
}
|
|
125937
|
+
}
|
|
125938
|
+
const pageItems = (result.data || []).filter((page) => page.page === targetPage);
|
|
125939
|
+
if (result.success && pageItems?.length) {
|
|
125940
|
+
setPages((prev2) => dedupeAndSortPages([...prev2, ...pageItems]));
|
|
125941
|
+
}
|
|
125942
|
+
if (!result.success && !responsePageSize) {
|
|
125943
|
+
shouldMarkAttempted = false;
|
|
125944
|
+
}
|
|
125945
|
+
} catch {
|
|
125946
|
+
console.error("Failed to fetch current page data");
|
|
125947
|
+
} finally {
|
|
125948
|
+
inFlightFallbackPagesRef.current.delete(targetPage);
|
|
125949
|
+
if (shouldMarkAttempted) {
|
|
125950
|
+
attemptedFallbackPagesRef.current.add(targetPage);
|
|
125951
|
+
}
|
|
125952
|
+
}
|
|
125953
|
+
}, [id, cloudContext, currentPage, loading, pages]);
|
|
125954
|
+
reactExports.useEffect(() => {
|
|
125955
|
+
taskPagesPageSizeRef.current = 100;
|
|
125956
|
+
attemptedFallbackPagesRef.current.clear();
|
|
125957
|
+
inFlightFallbackPagesRef.current.clear();
|
|
125958
|
+
}, [id]);
|
|
125893
125959
|
const loadPageImage = reactExports.useCallback(async () => {
|
|
125894
125960
|
if (!id || !currentPageData) {
|
|
125895
125961
|
setImageUrl(null);
|
|
@@ -125928,6 +125994,9 @@ const CloudPreview = () => {
|
|
|
125928
125994
|
reactExports.useEffect(() => {
|
|
125929
125995
|
loadPageImage();
|
|
125930
125996
|
}, [loadPageImage]);
|
|
125997
|
+
reactExports.useEffect(() => {
|
|
125998
|
+
ensureCurrentPageLoaded();
|
|
125999
|
+
}, [ensureCurrentPageLoaded]);
|
|
125931
126000
|
reactExports.useEffect(() => {
|
|
125932
126001
|
if (!id || !window.api?.events?.onCloudTaskEvent) return;
|
|
125933
126002
|
const handleEvent = (event) => {
|
package/dist/renderer/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>MarkPDFdown</title>
|
|
8
|
-
<script type="module" crossorigin src="./assets/index-
|
|
8
|
+
<script type="module" crossorigin src="./assets/index-DiGbhKeE.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="./assets/index-_4YzU2Gn.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/package.json
CHANGED