BlueGit

timfa filemanager

fix

timfa Tim Falken · pushed by timfa

Authored 2026-05-04 · 6 months ago

Hash
100f31a71d167f23372d3cf3926af8fe10d48ee8
Parent
e4614d13
1 file changed +35 −16
public/app.js +35 −16
@@ -1625,7 +1625,7 @@ function animateRect (el, fromRect, toRect, opts = {})
1625 1625 });
1626 1626 }
1627 1627
1628 async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectUrl)
1628 async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewContent)
1629 1629 {
1630 1630 if (!tileEl || !sourceSvgEl) return false;
1631 1631
@@ -1688,7 +1688,12 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU
1688 1688 dlBtn.addEventListener('click', (e) =>
1689 1689 {
1690 1690 e.stopPropagation();
1691 triggerDownload(item.name, objectUrl);
1691 if (!STATE.previewObjectUrl)
1692 {
1693 toast('Preview still loading.', 'err');
1694 return;
1695 }
1696 triggerDownload(item.name, STATE.previewObjectUrl);
1692 1697 });
1693 1698
1694 1699 iconEl.innerHTML = '';
@@ -1748,8 +1753,20 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU
1748 1753 tileEl.style.width = `${targetRect.width}px`;
1749 1754 tileEl.style.height = `${targetRect.height}px`;
1750 1755
1751 previewMount.innerHTML = '';
1752 await renderPreviewBody(item, blob, objectUrl, previewMount);
1756 try
1757 {
1758 await loadPreviewContent(previewMount);
1759 } catch
1760 {
1761 if (previewMount.isConnected)
1762 {
1763 previewMount.innerHTML = '';
1764 const msg = document.createElement('p');
1765 msg.className = 'preview-unsupported';
1766 msg.textContent = 'Preview failed to load. You can try again.';
1767 previewMount.appendChild(msg);
1768 }
1769 }
1753 1770
1754 1771 return true;
1755 1772 }
@@ -1916,22 +1933,24 @@ async function downloadOrView (item, sourceSvgEl = null)
1916 1933 await closePreview();
1917 1934 }
1918 1935
1919 const blob = await fetchFileBlob(item);
1920 if (!blob)
1921 {
1922 toast('Download failed.', 'err');
1923 return;
1924 }
1925
1926 clearPreviewObjectUrl();
1927 const objectUrl = URL.createObjectURL(blob);
1928 STATE.previewObjectUrl = objectUrl;
1929
1930 1936 const sourceTileEl = sourceSvgEl ? sourceSvgEl.closest('.file-item') : null;
1931 1937 if (sourceTileEl)
1932 1938 {
1933 1939 STATE.previewSourceEl = sourceSvgEl;
1934 const expanded = await openExpandedTilePreview(item, sourceTileEl, sourceSvgEl, blob, objectUrl);
1940 const expanded = await openExpandedTilePreview(item, sourceTileEl, sourceSvgEl, async (previewMount) =>
1941 {
1942 const blob = await fetchFileBlob(item);
1943 if (!blob) throw new Error('Download failed');
1944
1945 clearPreviewObjectUrl();
1946 const objectUrl = URL.createObjectURL(blob);
1947 STATE.previewObjectUrl = objectUrl;
1948
1949 if (!previewMount.isConnected) return;
1950
1951 previewMount.innerHTML = '';
1952 await renderPreviewBody(item, blob, objectUrl, previewMount);
1953 });
1935 1954 if (expanded) return;
1936 1955 }
1937 1956
@@ -1625,7 +1625,7 @@ function animateRect (el, fromRect, toRect, opts = {})
1625 });
1625 });
1626}
1626}
1627
1627
1628async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectUrl)
1628async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewContent)
1629{
1629{
1630 if (!tileEl || !sourceSvgEl) return false;
1630 if (!tileEl || !sourceSvgEl) return false;
1631
1631
@@ -1688,7 +1688,12 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU
1688 dlBtn.addEventListener('click', (e) =>
1688 dlBtn.addEventListener('click', (e) =>
1689 {
1689 {
1690 e.stopPropagation();
1690 e.stopPropagation();
1691 triggerDownload(item.name, objectUrl);
1691 if (!STATE.previewObjectUrl)
1692 {
1693 toast('Preview still loading.', 'err');
1694 return;
1695 }
1696 triggerDownload(item.name, STATE.previewObjectUrl);
1692 });
1697 });
1693
1698
1694 iconEl.innerHTML = '';
1699 iconEl.innerHTML = '';
@@ -1748,8 +1753,20 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU
1748 tileEl.style.width = `${targetRect.width}px`;
1753 tileEl.style.width = `${targetRect.width}px`;
1749 tileEl.style.height = `${targetRect.height}px`;
1754 tileEl.style.height = `${targetRect.height}px`;
1750
1755
1751 previewMount.innerHTML = '';
1756 try
1752 await renderPreviewBody(item, blob, objectUrl, previewMount);
1757 {
1758 await loadPreviewContent(previewMount);
1759 } catch
1760 {
1761 if (previewMount.isConnected)
1762 {
1763 previewMount.innerHTML = '';
1764 const msg = document.createElement('p');
1765 msg.className = 'preview-unsupported';
1766 msg.textContent = 'Preview failed to load. You can try again.';
1767 previewMount.appendChild(msg);
1768 }
1769 }
1753
1770
1754 return true;
1771 return true;
1755}
1772}
@@ -1916,22 +1933,24 @@ async function downloadOrView (item, sourceSvgEl = null)
1916 await closePreview();
1933 await closePreview();
1917 }
1934 }
1918
1935
1919 const blob = await fetchFileBlob(item);
1920 if (!blob)
1921 {
1922 toast('Download failed.', 'err');
1923 return;
1924 }
1925
1926 clearPreviewObjectUrl();
1927 const objectUrl = URL.createObjectURL(blob);
1928 STATE.previewObjectUrl = objectUrl;
1929
1930 const sourceTileEl = sourceSvgEl ? sourceSvgEl.closest('.file-item') : null;
1936 const sourceTileEl = sourceSvgEl ? sourceSvgEl.closest('.file-item') : null;
1931 if (sourceTileEl)
1937 if (sourceTileEl)
1932 {
1938 {
1933 STATE.previewSourceEl = sourceSvgEl;
1939 STATE.previewSourceEl = sourceSvgEl;
1934 const expanded = await openExpandedTilePreview(item, sourceTileEl, sourceSvgEl, blob, objectUrl);
1940 const expanded = await openExpandedTilePreview(item, sourceTileEl, sourceSvgEl, async (previewMount) =>
1941 {
1942 const blob = await fetchFileBlob(item);
1943 if (!blob) throw new Error('Download failed');
1944
1945 clearPreviewObjectUrl();
1946 const objectUrl = URL.createObjectURL(blob);
1947 STATE.previewObjectUrl = objectUrl;
1948
1949 if (!previewMount.isConnected) return;
1950
1951 previewMount.innerHTML = '';
1952 await renderPreviewBody(item, blob, objectUrl, previewMount);
1953 });
1935 if (expanded) return;
1954 if (expanded) return;
1936 }
1955 }
1937
1956