BlueGit

timfa filemanager

Add in-app balloon preview overlay with inline media/text rendering

timfa Tim Falken · pushed by timfa

Authored 2026-05-03 · 6 months ago

Hash
19c0a00b225a8e6c83755d508afed59832a7511b
Parent
787f4053
4 files changed +364 −33
.github/technical-reference.md +5 −0
@@ -33,6 +33,11 @@
33 33 - showConfirm(title, message) - In-page confirm dialog; returns Promise<boolean>. Use instead of window.confirm().
34 34 - showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().
35 35 - showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.
36 - fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.
37 - downloadOrView(item) - Opens the in-app file-preview overlay and attaches bottom download action.
38 - renderPreviewBody(item, blob, objectUrl) - Renders preview content (image/video/audio/pdf/text) or unsupported message.
39 - closePreview() - Closes preview overlay and revokes active preview object URL.
40 - isInlinePreviewableBlob(blob, name) - Determines if a blob can be previewed inline by MIME/extension.
36 41
37 42 ## tests/auth.routes.test.js
38 43 - session lifecycle / POST /api/auth/logout revokes active session - Verifies explicit logout invalidates token immediately.
@@ -33,6 +33,11 @@
33- showConfirm(title, message) - In-page confirm dialog; returns Promise<boolean>. Use instead of window.confirm().
33- showConfirm(title, message) - In-page confirm dialog; returns Promise<boolean>. Use instead of window.confirm().
34- showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().
34- showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().
35- showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.
35- showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.
36- fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.
37- downloadOrView(item) - Opens the in-app file-preview overlay and attaches bottom download action.
38- renderPreviewBody(item, blob, objectUrl) - Renders preview content (image/video/audio/pdf/text) or unsupported message.
39- closePreview() - Closes preview overlay and revokes active preview object URL.
40- isInlinePreviewableBlob(blob, name) - Determines if a blob can be previewed inline by MIME/extension.
36
41
37## tests/auth.routes.test.js
42## tests/auth.routes.test.js
38- session lifecycle / POST /api/auth/logout revokes active session - Verifies explicit logout invalidates token immediately.
43- session lifecycle / POST /api/auth/logout revokes active session - Verifies explicit logout invalidates token immediately.
public/app.js +182 −33
@@ -43,6 +43,9 @@ const STATE = {
43 43 uploadInProgress: false,
44 44 // Blob URLs for thumbnail previews — revoked on each grid rebuild
45 45 thumbnailUrls: [],
46
47 // Preview overlay state
48 previewObjectUrl: null,
46 49 };
47 50
48 51 const SESSION_KEY = 'filemanager.session.v1';
@@ -630,6 +633,7 @@ async function performLogout ()
630 633 STATE.restoreRootPath = null;
631 634 STATE.lastOperationAt = null;
632 635 clearSessionState();
636 closePreview();
633 637 closeSidebar();
634 638 await initAuth();
635 639 }
@@ -887,7 +891,8 @@ function makeFileItem (item)
887 891 const icon = document.createElement('div');
888 892 icon.className = 'icon';
889 893 icon.innerHTML = item.isDir ? iconFolder() : iconFile(item.name);
890 if (!item.isDir && IMAGE_EXTS.has(extOf(item.name))) {
894 if (!item.isDir && IMAGE_EXTS.has(extOf(item.name)))
895 {
891 896 icon.dataset.previewPath = item.path;
892 897 }
893 898 el.appendChild(icon);
@@ -1009,20 +1014,52 @@ function closeSidebar ()
1009 1014 // DOWNLOAD / VIEW
1010 1015 // ───────────────────────────────────────────────────────────────────────────
1011 1016
1012 function downloadOrView (item)
1017 function isInlinePreviewableBlob (blob, name)
1013 1018 {
1014 const url = `/api/files/download?file=${encodeURIComponent(item.path)}`;
1015 // Open in new tab — browser decides whether to display or download
1016 const a = document.createElement('a');
1017 a.href = url;
1018 a.target = '_blank';
1019 a.rel = 'noopener noreferrer';
1020 // We need to send the auth header; since <a> can't do that, we fetch and blob it
1021 fetchAndServe(item, url);
1019 const mime = String(blob.type || '').toLowerCase();
1020 if (/^(image|video|audio)\//.test(mime)) return true;
1021 if (/^text\//.test(mime)) return true;
1022 if (mime === 'application/pdf') return true;
1023 if (mime === 'application/json') return true;
1024 if (mime === 'application/xml') return true;
1025 if (mime === 'application/javascript') return true;
1026
1027 // Fallback by extension when MIME is missing or generic.
1028 const ext = extOf(name || '');
1029 if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext) || AUDIO_EXTS.has(ext)) return true;
1030 if (CODE_EXTS.has(ext)) return true;
1031 return false;
1032 }
1033
1034 function isTextLikeBlob (blob, name)
1035 {
1036 const mime = String(blob.type || '').toLowerCase();
1037 if (/^text\//.test(mime)) return true;
1038 if (mime === 'application/json' || mime === 'application/xml' || mime === 'application/javascript') return true;
1039 const ext = extOf(name || '');
1040 return CODE_EXTS.has(ext);
1041 }
1042
1043 function clearPreviewObjectUrl ()
1044 {
1045 if (!STATE.previewObjectUrl) return;
1046 URL.revokeObjectURL(STATE.previewObjectUrl);
1047 STATE.previewObjectUrl = null;
1022 1048 }
1023 1049
1024 async function fetchAndServe (item, url)
1050 function closePreview ()
1025 1051 {
1052 const overlay = document.getElementById('preview-overlay');
1053 const body = document.getElementById('preview-body');
1054 if (!overlay || !body) return;
1055 overlay.classList.add('hidden');
1056 body.innerHTML = '';
1057 clearPreviewObjectUrl();
1058 }
1059
1060 async function fetchFileBlob (item)
1061 {
1062 const url = `/api/files/download?file=${encodeURIComponent(item.path)}`;
1026 1063 try
1027 1064 {
1028 1065 const res = await fetch(url, {
@@ -1031,26 +1068,117 @@ async function fetchAndServe (item, url)
1031 1068 'X-Fp': getFingerprint(),
1032 1069 },
1033 1070 });
1034 if (!res.ok) { toast('Download failed.', 'err'); return; }
1035 const blob = await res.blob();
1036 const objUrl = URL.createObjectURL(blob);
1037 const a = document.createElement('a');
1038 a.href = objUrl;
1039 a.download = item.name;
1040 // Try to open viewable types inline
1041 const viewable = /^(image|video|audio|text|application\/pdf)/.test(blob.type);
1042 if (viewable)
1043 {
1044 window.open(objUrl, '_blank', 'noopener,noreferrer');
1045 } else
1046 {
1047 a.click();
1048 }
1049 setTimeout(() => URL.revokeObjectURL(objUrl), 60000);
1071 if (!res.ok) throw new Error('Download failed.');
1072 return await res.blob();
1050 1073 } catch
1074 {
1075 return null;
1076 }
1077 }
1078
1079 function triggerDownload (filename, objectUrl)
1080 {
1081 const a = document.createElement('a');
1082 a.href = objectUrl;
1083 a.download = filename;
1084 a.click();
1085 }
1086
1087 async function renderPreviewBody (item, blob, objectUrl)
1088 {
1089 const body = document.getElementById('preview-body');
1090 body.innerHTML = '';
1091
1092 const mime = String(blob.type || '').toLowerCase();
1093 const previewable = isInlinePreviewableBlob(blob, item.name);
1094
1095 if (!previewable)
1096 {
1097 const msg = document.createElement('p');
1098 msg.className = 'preview-unsupported';
1099 msg.textContent = 'This file cannot be previewed, but you can download it with the button below.';
1100 body.appendChild(msg);
1101 return;
1102 }
1103
1104 if (/^image\//.test(mime) || IMAGE_EXTS.has(extOf(item.name)))
1105 {
1106 const img = document.createElement('img');
1107 img.className = 'preview-media';
1108 img.src = objectUrl;
1109 img.alt = item.name;
1110 body.appendChild(img);
1111 return;
1112 }
1113
1114 if (/^video\//.test(mime) || VIDEO_EXTS.has(extOf(item.name)))
1115 {
1116 const video = document.createElement('video');
1117 video.className = 'preview-media';
1118 video.src = objectUrl;
1119 video.controls = true;
1120 video.preload = 'metadata';
1121 body.appendChild(video);
1122 return;
1123 }
1124
1125 if (/^audio\//.test(mime) || AUDIO_EXTS.has(extOf(item.name)))
1126 {
1127 const audio = document.createElement('audio');
1128 audio.className = 'preview-audio';
1129 audio.src = objectUrl;
1130 audio.controls = true;
1131 body.appendChild(audio);
1132 return;
1133 }
1134
1135 if (mime === 'application/pdf')
1136 {
1137 const frame = document.createElement('iframe');
1138 frame.className = 'preview-frame';
1139 frame.src = objectUrl;
1140 frame.title = item.name;
1141 body.appendChild(frame);
1142 return;
1143 }
1144
1145 if (isTextLikeBlob(blob, item.name))
1146 {
1147 const text = await blob.text();
1148 const pre = document.createElement('pre');
1149 pre.className = 'preview-text';
1150 pre.textContent = text;
1151 body.appendChild(pre);
1152 return;
1153 }
1154
1155 const msg = document.createElement('p');
1156 msg.className = 'preview-unsupported';
1157 msg.textContent = 'This file cannot be previewed, but you can download it with the button below.';
1158 body.appendChild(msg);
1159 }
1160
1161 async function downloadOrView (item)
1162 {
1163 const blob = await fetchFileBlob(item);
1164 if (!blob)
1051 1165 {
1052 1166 toast('Download failed.', 'err');
1167 return;
1053 1168 }
1169
1170 clearPreviewObjectUrl();
1171 const objectUrl = URL.createObjectURL(blob);
1172 STATE.previewObjectUrl = objectUrl;
1173
1174 const overlay = document.getElementById('preview-overlay');
1175 const title = document.getElementById('preview-title');
1176 const dlBtn = document.getElementById('preview-download');
1177
1178 title.textContent = item.name;
1179 dlBtn.onclick = () => triggerDownload(item.name, objectUrl);
1180 await renderPreviewBody(item, blob, objectUrl);
1181 overlay.classList.remove('hidden');
1054 1182 }
1055 1183
1056 1184 // ───────────────────────────────────────────────────────────────────────────
@@ -1643,18 +1771,22 @@ function iconFile (name, size = 52)
1643 1771 // THUMBNAIL PREVIEWS
1644 1772 // ───────────────────────────────────────────────────────────────────────────
1645 1773
1646 function revokeThumbnails () {
1774 function revokeThumbnails ()
1775 {
1647 1776 STATE.thumbnailUrls.forEach(u => URL.revokeObjectURL(u));
1648 1777 STATE.thumbnailUrls = [];
1649 1778 }
1650 1779
1651 async function loadThumbnails () {
1780 async function loadThumbnails ()
1781 {
1652 1782 const icons = Array.from(document.querySelectorAll('.icon[data-preview-path]'));
1653 1783 if (!icons.length) return;
1654 1784
1655 1785 const queue = [...icons];
1656 async function worker () {
1657 while (queue.length) {
1786 async function worker ()
1787 {
1788 while (queue.length)
1789 {
1658 1790 await loadOneThumbnail(queue.shift());
1659 1791 }
1660 1792 }
@@ -1662,13 +1794,15 @@ async function loadThumbnails () {
1662 1794 await Promise.all(Array.from({ length: Math.min(4, icons.length) }, worker));
1663 1795 }
1664 1796
1665 async function loadOneThumbnail (iconEl) {
1797 async function loadOneThumbnail (iconEl)
1798 {
1666 1799 if (!iconEl.isConnected || !STATE.token) return;
1667 1800 const filePath = iconEl.dataset.previewPath;
1668 1801 const url = `/api/files/download?file=${encodeURIComponent(filePath)}`;
1669 1802
1670 1803 let res;
1671 try {
1804 try
1805 {
1672 1806 res = await fetch(url, { headers: { Authorization: `Bearer ${STATE.token}` } });
1673 1807 } catch { return; }
1674 1808 if (!res.ok || !iconEl.isConnected) return;
@@ -1867,6 +2001,21 @@ function wireEvents ()
1867 2001 document.getElementById('rename-modal-close').addEventListener('click', () =>
1868 2002 document.getElementById('rename-modal').classList.add('hidden'));
1869 2003
2004 // Preview close
2005 document.getElementById('preview-close').addEventListener('click', closePreview);
2006 document.getElementById('preview-overlay').addEventListener('click', (e) =>
2007 {
2008 if (e.target.id === 'preview-overlay') closePreview();
2009 });
2010
2011 document.addEventListener('keydown', (e) =>
2012 {
2013 if (e.key === 'Escape' && !document.getElementById('preview-overlay').classList.contains('hidden'))
2014 {
2015 closePreview();
2016 }
2017 });
2018
1870 2019 // Close modals on backdrop click
1871 2020 document.querySelectorAll('.modal-overlay').forEach(overlay =>
1872 2021 {
@@ -43,6 +43,9 @@ const STATE = {
43 uploadInProgress: false,
43 uploadInProgress: false,
44 // Blob URLs for thumbnail previews — revoked on each grid rebuild
44 // Blob URLs for thumbnail previews — revoked on each grid rebuild
45 thumbnailUrls: [],
45 thumbnailUrls: [],
46
47 // Preview overlay state
48 previewObjectUrl: null,
46};
49};
47
50
48const SESSION_KEY = 'filemanager.session.v1';
51const SESSION_KEY = 'filemanager.session.v1';
@@ -630,6 +633,7 @@ async function performLogout ()
630 STATE.restoreRootPath = null;
633 STATE.restoreRootPath = null;
631 STATE.lastOperationAt = null;
634 STATE.lastOperationAt = null;
632 clearSessionState();
635 clearSessionState();
636 closePreview();
633 closeSidebar();
637 closeSidebar();
634 await initAuth();
638 await initAuth();
635}
639}
@@ -887,7 +891,8 @@ function makeFileItem (item)
887 const icon = document.createElement('div');
891 const icon = document.createElement('div');
888 icon.className = 'icon';
892 icon.className = 'icon';
889 icon.innerHTML = item.isDir ? iconFolder() : iconFile(item.name);
893 icon.innerHTML = item.isDir ? iconFolder() : iconFile(item.name);
890 if (!item.isDir && IMAGE_EXTS.has(extOf(item.name))) {
894 if (!item.isDir && IMAGE_EXTS.has(extOf(item.name)))
895 {
891 icon.dataset.previewPath = item.path;
896 icon.dataset.previewPath = item.path;
892 }
897 }
893 el.appendChild(icon);
898 el.appendChild(icon);
@@ -1009,20 +1014,52 @@ function closeSidebar ()
1009// DOWNLOAD / VIEW
1014// DOWNLOAD / VIEW
1010// ───────────────────────────────────────────────────────────────────────────
1015// ───────────────────────────────────────────────────────────────────────────
1011
1016
1012function downloadOrView (item)
1017function isInlinePreviewableBlob (blob, name)
1013{
1018{
1014 const url = `/api/files/download?file=${encodeURIComponent(item.path)}`;
1019 const mime = String(blob.type || '').toLowerCase();
1015 // Open in new tab — browser decides whether to display or download
1020 if (/^(image|video|audio)\//.test(mime)) return true;
1016 const a = document.createElement('a');
1021 if (/^text\//.test(mime)) return true;
1017 a.href = url;
1022 if (mime === 'application/pdf') return true;
1018 a.target = '_blank';
1023 if (mime === 'application/json') return true;
1019 a.rel = 'noopener noreferrer';
1024 if (mime === 'application/xml') return true;
1020 // We need to send the auth header; since <a> can't do that, we fetch and blob it
1025 if (mime === 'application/javascript') return true;
1021 fetchAndServe(item, url);
1026
1027 // Fallback by extension when MIME is missing or generic.
1028 const ext = extOf(name || '');
1029 if (IMAGE_EXTS.has(ext) || VIDEO_EXTS.has(ext) || AUDIO_EXTS.has(ext)) return true;
1030 if (CODE_EXTS.has(ext)) return true;
1031 return false;
1032}
1033
1034function isTextLikeBlob (blob, name)
1035{
1036 const mime = String(blob.type || '').toLowerCase();
1037 if (/^text\//.test(mime)) return true;
1038 if (mime === 'application/json' || mime === 'application/xml' || mime === 'application/javascript') return true;
1039 const ext = extOf(name || '');
1040 return CODE_EXTS.has(ext);
1041}
1042
1043function clearPreviewObjectUrl ()
1044{
1045 if (!STATE.previewObjectUrl) return;
1046 URL.revokeObjectURL(STATE.previewObjectUrl);
1047 STATE.previewObjectUrl = null;
1022}
1048}
1023
1049
1024async function fetchAndServe (item, url)
1050function closePreview ()
1025{
1051{
1052 const overlay = document.getElementById('preview-overlay');
1053 const body = document.getElementById('preview-body');
1054 if (!overlay || !body) return;
1055 overlay.classList.add('hidden');
1056 body.innerHTML = '';
1057 clearPreviewObjectUrl();
1058}
1059
1060async function fetchFileBlob (item)
1061{
1062 const url = `/api/files/download?file=${encodeURIComponent(item.path)}`;
1026 try
1063 try
1027 {
1064 {
1028 const res = await fetch(url, {
1065 const res = await fetch(url, {
@@ -1031,26 +1068,117 @@ async function fetchAndServe (item, url)
1031 'X-Fp': getFingerprint(),
1068 'X-Fp': getFingerprint(),
1032 },
1069 },
1033 });
1070 });
1034 if (!res.ok) { toast('Download failed.', 'err'); return; }
1071 if (!res.ok) throw new Error('Download failed.');
1035 const blob = await res.blob();
1072 return await res.blob();
1036 const objUrl = URL.createObjectURL(blob);
1037 const a = document.createElement('a');
1038 a.href = objUrl;
1039 a.download = item.name;
1040 // Try to open viewable types inline
1041 const viewable = /^(image|video|audio|text|application\/pdf)/.test(blob.type);
1042 if (viewable)
1043 {
1044 window.open(objUrl, '_blank', 'noopener,noreferrer');
1045 } else
1046 {
1047 a.click();
1048 }
1049 setTimeout(() => URL.revokeObjectURL(objUrl), 60000);
1050 } catch
1073 } catch
1074 {
1075 return null;
1076 }
1077}
1078
1079function triggerDownload (filename, objectUrl)
1080{
1081 const a = document.createElement('a');
1082 a.href = objectUrl;
1083 a.download = filename;
1084 a.click();
1085}
1086
1087async function renderPreviewBody (item, blob, objectUrl)
1088{
1089 const body = document.getElementById('preview-body');
1090 body.innerHTML = '';
1091
1092 const mime = String(blob.type || '').toLowerCase();
1093 const previewable = isInlinePreviewableBlob(blob, item.name);
1094
1095 if (!previewable)
1096 {
1097 const msg = document.createElement('p');
1098 msg.className = 'preview-unsupported';
1099 msg.textContent = 'This file cannot be previewed, but you can download it with the button below.';
1100 body.appendChild(msg);
1101 return;
1102 }
1103
1104 if (/^image\//.test(mime) || IMAGE_EXTS.has(extOf(item.name)))
1105 {
1106 const img = document.createElement('img');
1107 img.className = 'preview-media';
1108 img.src = objectUrl;
1109 img.alt = item.name;
1110 body.appendChild(img);
1111 return;
1112 }
1113
1114 if (/^video\//.test(mime) || VIDEO_EXTS.has(extOf(item.name)))
1115 {
1116 const video = document.createElement('video');
1117 video.className = 'preview-media';
1118 video.src = objectUrl;
1119 video.controls = true;
1120 video.preload = 'metadata';
1121 body.appendChild(video);
1122 return;
1123 }
1124
1125 if (/^audio\//.test(mime) || AUDIO_EXTS.has(extOf(item.name)))
1126 {
1127 const audio = document.createElement('audio');
1128 audio.className = 'preview-audio';
1129 audio.src = objectUrl;
1130 audio.controls = true;
1131 body.appendChild(audio);
1132 return;
1133 }
1134
1135 if (mime === 'application/pdf')
1136 {
1137 const frame = document.createElement('iframe');
1138 frame.className = 'preview-frame';
1139 frame.src = objectUrl;
1140 frame.title = item.name;
1141 body.appendChild(frame);
1142 return;
1143 }
1144
1145 if (isTextLikeBlob(blob, item.name))
1146 {
1147 const text = await blob.text();
1148 const pre = document.createElement('pre');
1149 pre.className = 'preview-text';
1150 pre.textContent = text;
1151 body.appendChild(pre);
1152 return;
1153 }
1154
1155 const msg = document.createElement('p');
1156 msg.className = 'preview-unsupported';
1157 msg.textContent = 'This file cannot be previewed, but you can download it with the button below.';
1158 body.appendChild(msg);
1159}
1160
1161async function downloadOrView (item)
1162{
1163 const blob = await fetchFileBlob(item);
1164 if (!blob)
1051 {
1165 {
1052 toast('Download failed.', 'err');
1166 toast('Download failed.', 'err');
1167 return;
1053 }
1168 }
1169
1170 clearPreviewObjectUrl();
1171 const objectUrl = URL.createObjectURL(blob);
1172 STATE.previewObjectUrl = objectUrl;
1173
1174 const overlay = document.getElementById('preview-overlay');
1175 const title = document.getElementById('preview-title');
1176 const dlBtn = document.getElementById('preview-download');
1177
1178 title.textContent = item.name;
1179 dlBtn.onclick = () => triggerDownload(item.name, objectUrl);
1180 await renderPreviewBody(item, blob, objectUrl);
1181 overlay.classList.remove('hidden');
1054}
1182}
1055
1183
1056// ───────────────────────────────────────────────────────────────────────────
1184// ───────────────────────────────────────────────────────────────────────────
@@ -1643,18 +1771,22 @@ function iconFile (name, size = 52)
1643// THUMBNAIL PREVIEWS
1771// THUMBNAIL PREVIEWS
1644// ───────────────────────────────────────────────────────────────────────────
1772// ───────────────────────────────────────────────────────────────────────────
1645
1773
1646function revokeThumbnails () {
1774function revokeThumbnails ()
1775{
1647 STATE.thumbnailUrls.forEach(u => URL.revokeObjectURL(u));
1776 STATE.thumbnailUrls.forEach(u => URL.revokeObjectURL(u));
1648 STATE.thumbnailUrls = [];
1777 STATE.thumbnailUrls = [];
1649}
1778}
1650
1779
1651async function loadThumbnails () {
1780async function loadThumbnails ()
1781{
1652 const icons = Array.from(document.querySelectorAll('.icon[data-preview-path]'));
1782 const icons = Array.from(document.querySelectorAll('.icon[data-preview-path]'));
1653 if (!icons.length) return;
1783 if (!icons.length) return;
1654
1784
1655 const queue = [...icons];
1785 const queue = [...icons];
1656 async function worker () {
1786 async function worker ()
1657 while (queue.length) {
1787 {
1788 while (queue.length)
1789 {
1658 await loadOneThumbnail(queue.shift());
1790 await loadOneThumbnail(queue.shift());
1659 }
1791 }
1660 }
1792 }
@@ -1662,13 +1794,15 @@ async function loadThumbnails () {
1662 await Promise.all(Array.from({ length: Math.min(4, icons.length) }, worker));
1794 await Promise.all(Array.from({ length: Math.min(4, icons.length) }, worker));
1663}
1795}
1664
1796
1665async function loadOneThumbnail (iconEl) {
1797async function loadOneThumbnail (iconEl)
1798{
1666 if (!iconEl.isConnected || !STATE.token) return;
1799 if (!iconEl.isConnected || !STATE.token) return;
1667 const filePath = iconEl.dataset.previewPath;
1800 const filePath = iconEl.dataset.previewPath;
1668 const url = `/api/files/download?file=${encodeURIComponent(filePath)}`;
1801 const url = `/api/files/download?file=${encodeURIComponent(filePath)}`;
1669
1802
1670 let res;
1803 let res;
1671 try {
1804 try
1805 {
1672 res = await fetch(url, { headers: { Authorization: `Bearer ${STATE.token}` } });
1806 res = await fetch(url, { headers: { Authorization: `Bearer ${STATE.token}` } });
1673 } catch { return; }
1807 } catch { return; }
1674 if (!res.ok || !iconEl.isConnected) return;
1808 if (!res.ok || !iconEl.isConnected) return;
@@ -1867,6 +2001,21 @@ function wireEvents ()
1867 document.getElementById('rename-modal-close').addEventListener('click', () =>
2001 document.getElementById('rename-modal-close').addEventListener('click', () =>
1868 document.getElementById('rename-modal').classList.add('hidden'));
2002 document.getElementById('rename-modal').classList.add('hidden'));
1869
2003
2004 // Preview close
2005 document.getElementById('preview-close').addEventListener('click', closePreview);
2006 document.getElementById('preview-overlay').addEventListener('click', (e) =>
2007 {
2008 if (e.target.id === 'preview-overlay') closePreview();
2009 });
2010
2011 document.addEventListener('keydown', (e) =>
2012 {
2013 if (e.key === 'Escape' && !document.getElementById('preview-overlay').classList.contains('hidden'))
2014 {
2015 closePreview();
2016 }
2017 });
2018
1870 // Close modals on backdrop click
2019 // Close modals on backdrop click
1871 document.querySelectorAll('.modal-overlay').forEach(overlay =>
2020 document.querySelectorAll('.modal-overlay').forEach(overlay =>
1872 {
2021 {
public/index.html +14 −0
@@ -249,6 +249,20 @@
249 249 </div>
250 250 </div>
251 251
252 <!-- FILE PREVIEW OVERLAY -->
253 <div id="preview-overlay" class="preview-overlay hidden" role="dialog" aria-modal="true"
254 aria-labelledby="preview-title">
255 <div id="preview-sheet" class="preview-sheet" role="document">
256 <div class="preview-fold" aria-hidden="true"></div>
257 <button id="preview-close" class="preview-close" aria-label="Close preview">✕</button>
258 <h2 id="preview-title" class="preview-title"></h2>
259 <div id="preview-body" class="preview-body"></div>
260 <div class="preview-footer">
261 <button id="preview-download" class="primary">Download</button>
262 </div>
263 </div>
264 </div>
265
252 266 <!-- TOAST -->
253 267 <div id="toast" aria-live="assertive" aria-atomic="true"></div>
254 268
@@ -249,6 +249,20 @@
249 </div>
249 </div>
250 </div>
250 </div>
251
251
252 <!-- FILE PREVIEW OVERLAY -->
253 <div id="preview-overlay" class="preview-overlay hidden" role="dialog" aria-modal="true"
254 aria-labelledby="preview-title">
255 <div id="preview-sheet" class="preview-sheet" role="document">
256 <div class="preview-fold" aria-hidden="true"></div>
257 <button id="preview-close" class="preview-close" aria-label="Close preview">✕</button>
258 <h2 id="preview-title" class="preview-title"></h2>
259 <div id="preview-body" class="preview-body"></div>
260 <div class="preview-footer">
261 <button id="preview-download" class="primary">Download</button>
262 </div>
263 </div>
264 </div>
265
252 <!-- TOAST -->
266 <!-- TOAST -->
253 <div id="toast" aria-live="assertive" aria-atomic="true"></div>
267 <div id="toast" aria-live="assertive" aria-atomic="true"></div>
254
268
public/style.css +163 −0
@@ -617,6 +617,150 @@ button.danger:hover {
617 617 border-color: var(--accent);
618 618 }
619 619
620 /* =========================================================
621 FILE PREVIEW OVERLAY
622 ========================================================= */
623 .preview-overlay {
624 position: fixed;
625 inset: 0;
626 z-index: 120;
627 background: rgba(8, 9, 14, 0.82);
628 display: flex;
629 align-items: center;
630 justify-content: center;
631 padding: 2rem;
632 }
633
634 .preview-sheet {
635 position: relative;
636 width: min(94vw, 1100px);
637 height: min(90vh, 860px);
638 border: 2px solid #3fcf8e;
639 border-radius: 12px;
640 background: linear-gradient(180deg, #151925 0%, #111521 100%);
641 box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
642 display: flex;
643 flex-direction: column;
644 overflow: hidden;
645 animation: preview-balloon 220ms cubic-bezier(0.2, 0.9, 0.2, 1.05);
646 }
647
648 .preview-fold {
649 position: absolute;
650 top: 0;
651 right: 0;
652 width: 64px;
653 height: 64px;
654 background: linear-gradient(135deg, #182135 0%, #0f1525 100%);
655 clip-path: polygon(100% 0, 100% 100%, 0 0);
656 border-left: 1px solid rgba(63, 207, 142, 0.45);
657 border-bottom: 1px solid rgba(63, 207, 142, 0.45);
658 }
659
660 .preview-close {
661 position: absolute;
662 top: 8px;
663 right: 8px;
664 width: 28px;
665 height: 28px;
666 background: transparent;
667 color: #d6deef;
668 border-radius: 999px;
669 font-size: 0.95rem;
670 z-index: 2;
671 }
672
673 .preview-close:hover {
674 background: rgba(255, 255, 255, 0.08);
675 }
676
677 .preview-title {
678 font-size: 1rem;
679 color: var(--text);
680 padding: 0.85rem 1rem;
681 margin: 0;
682 border-bottom: 1px solid var(--border);
683 white-space: nowrap;
684 overflow: hidden;
685 text-overflow: ellipsis;
686 padding-right: 3.5rem;
687 }
688
689 .preview-body {
690 flex: 1;
691 min-height: 0;
692 overflow: auto;
693 display: flex;
694 align-items: center;
695 justify-content: center;
696 padding: 0.9rem;
697 }
698
699 .preview-media {
700 max-width: 100%;
701 max-height: 100%;
702 width: auto;
703 height: auto;
704 object-fit: contain;
705 }
706
707 .preview-frame {
708 width: 100%;
709 height: 100%;
710 border: none;
711 border-radius: 8px;
712 background: #fff;
713 }
714
715 .preview-audio {
716 width: min(640px, 95%);
717 }
718
719 .preview-text {
720 width: 100%;
721 min-height: 100%;
722 color: #dce4ff;
723 background: #0d111a;
724 border: 1px solid var(--border);
725 border-radius: 8px;
726 padding: 0.9rem;
727 font: 0.85rem/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
728 overflow: auto;
729 white-space: pre;
730 }
731
732 .preview-unsupported {
733 color: var(--text-muted);
734 font-size: 0.95rem;
735 max-width: 56ch;
736 text-align: center;
737 }
738
739 .preview-footer {
740 border-top: 1px solid var(--border);
741 padding: 0.8rem 1rem;
742 display: flex;
743 justify-content: flex-end;
744 }
745
746 .preview-footer .primary {
747 width: auto;
748 margin-top: 0;
749 min-width: 8rem;
750 }
751
752 @keyframes preview-balloon {
753 from {
754 opacity: 0;
755 transform: scale(0.12);
756 }
757
758 to {
759 opacity: 1;
760 transform: scale(1);
761 }
762 }
763
620 764 /* =========================================================
621 765 TOAST
622 766 ========================================================= */
@@ -744,6 +888,25 @@ button.danger:hover {
744 888 .modal {
745 889 padding: 1.25rem;
746 890 }
891
892 .preview-overlay {
893 padding: 0.8rem;
894 }
895
896 .preview-sheet {
897 width: 100%;
898 height: 92vh;
899 }
900
901 .preview-fold {
902 width: 54px;
903 height: 54px;
904 }
905
906 .preview-close {
907 top: 5px;
908 right: 5px;
909 }
747 910 }
748 911
749 912 /* =========================================================
@@ -617,6 +617,150 @@ button.danger:hover {
617 border-color: var(--accent);
617 border-color: var(--accent);
618}
618}
619
619
620/* =========================================================
621 FILE PREVIEW OVERLAY
622 ========================================================= */
623.preview-overlay {
624 position: fixed;
625 inset: 0;
626 z-index: 120;
627 background: rgba(8, 9, 14, 0.82);
628 display: flex;
629 align-items: center;
630 justify-content: center;
631 padding: 2rem;
632}
633
634.preview-sheet {
635 position: relative;
636 width: min(94vw, 1100px);
637 height: min(90vh, 860px);
638 border: 2px solid #3fcf8e;
639 border-radius: 12px;
640 background: linear-gradient(180deg, #151925 0%, #111521 100%);
641 box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
642 display: flex;
643 flex-direction: column;
644 overflow: hidden;
645 animation: preview-balloon 220ms cubic-bezier(0.2, 0.9, 0.2, 1.05);
646}
647
648.preview-fold {
649 position: absolute;
650 top: 0;
651 right: 0;
652 width: 64px;
653 height: 64px;
654 background: linear-gradient(135deg, #182135 0%, #0f1525 100%);
655 clip-path: polygon(100% 0, 100% 100%, 0 0);
656 border-left: 1px solid rgba(63, 207, 142, 0.45);
657 border-bottom: 1px solid rgba(63, 207, 142, 0.45);
658}
659
660.preview-close {
661 position: absolute;
662 top: 8px;
663 right: 8px;
664 width: 28px;
665 height: 28px;
666 background: transparent;
667 color: #d6deef;
668 border-radius: 999px;
669 font-size: 0.95rem;
670 z-index: 2;
671}
672
673.preview-close:hover {
674 background: rgba(255, 255, 255, 0.08);
675}
676
677.preview-title {
678 font-size: 1rem;
679 color: var(--text);
680 padding: 0.85rem 1rem;
681 margin: 0;
682 border-bottom: 1px solid var(--border);
683 white-space: nowrap;
684 overflow: hidden;
685 text-overflow: ellipsis;
686 padding-right: 3.5rem;
687}
688
689.preview-body {
690 flex: 1;
691 min-height: 0;
692 overflow: auto;
693 display: flex;
694 align-items: center;
695 justify-content: center;
696 padding: 0.9rem;
697}
698
699.preview-media {
700 max-width: 100%;
701 max-height: 100%;
702 width: auto;
703 height: auto;
704 object-fit: contain;
705}
706
707.preview-frame {
708 width: 100%;
709 height: 100%;
710 border: none;
711 border-radius: 8px;
712 background: #fff;
713}
714
715.preview-audio {
716 width: min(640px, 95%);
717}
718
719.preview-text {
720 width: 100%;
721 min-height: 100%;
722 color: #dce4ff;
723 background: #0d111a;
724 border: 1px solid var(--border);
725 border-radius: 8px;
726 padding: 0.9rem;
727 font: 0.85rem/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
728 overflow: auto;
729 white-space: pre;
730}
731
732.preview-unsupported {
733 color: var(--text-muted);
734 font-size: 0.95rem;
735 max-width: 56ch;
736 text-align: center;
737}
738
739.preview-footer {
740 border-top: 1px solid var(--border);
741 padding: 0.8rem 1rem;
742 display: flex;
743 justify-content: flex-end;
744}
745
746.preview-footer .primary {
747 width: auto;
748 margin-top: 0;
749 min-width: 8rem;
750}
751
752@keyframes preview-balloon {
753 from {
754 opacity: 0;
755 transform: scale(0.12);
756 }
757
758 to {
759 opacity: 1;
760 transform: scale(1);
761 }
762}
763
620/* =========================================================
764/* =========================================================
621 TOAST
765 TOAST
622 ========================================================= */
766 ========================================================= */
@@ -744,6 +888,25 @@ button.danger:hover {
744 .modal {
888 .modal {
745 padding: 1.25rem;
889 padding: 1.25rem;
746 }
890 }
891
892 .preview-overlay {
893 padding: 0.8rem;
894 }
895
896 .preview-sheet {
897 width: 100%;
898 height: 92vh;
899 }
900
901 .preview-fold {
902 width: 54px;
903 height: 54px;
904 }
905
906 .preview-close {
907 top: 5px;
908 right: 5px;
909 }
747}
910}
748
911
749/* =========================================================
912/* =========================================================