Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- dashboardlogic.js +39 -4
dashboardlogic.js
CHANGED
|
@@ -177,6 +177,7 @@ async function loadFiles() {
|
|
| 177 |
render(files);
|
| 178 |
loading(false);
|
| 179 |
console.log('✓ Files loaded and rendered');
|
|
|
|
| 180 |
} catch (err) {
|
| 181 |
console.error('Files load error:', err);
|
| 182 |
loading(false);
|
|
@@ -189,6 +190,32 @@ async function loadFiles() {
|
|
| 189 |
}
|
| 190 |
}
|
| 191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
// Update stats cards
|
| 193 |
function updateStatsCards() {
|
| 194 |
const cards = document.querySelectorAll('.card');
|
|
@@ -233,14 +260,22 @@ function render(list) {
|
|
| 233 |
}
|
| 234 |
|
| 235 |
// Grid HTML
|
| 236 |
-
const gridHTML = list.map((f, i) =>
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
<span class="fc-check"><i class="fa-solid fa-check"></i></span>
|
| 239 |
-
<span class="fc-icon">${
|
| 240 |
<span class="fc-name">${f.name}</span>
|
| 241 |
<span class="fc-meta">${f.size}</span>
|
| 242 |
</div>
|
| 243 |
-
`
|
|
|
|
| 244 |
|
| 245 |
grid.innerHTML = gridHTML;
|
| 246 |
console.log('Grid rendered with', list.length, 'items');
|
|
|
|
| 177 |
render(files);
|
| 178 |
loading(false);
|
| 179 |
console.log('✓ Files loaded and rendered');
|
| 180 |
+
preloadTextPreviews();
|
| 181 |
} catch (err) {
|
| 182 |
console.error('Files load error:', err);
|
| 183 |
loading(false);
|
|
|
|
| 190 |
}
|
| 191 |
}
|
| 192 |
|
| 193 |
+
// Preload short text previews for text files so grid view
|
| 194 |
+
// can show the first few words instead of just an icon.
|
| 195 |
+
async function preloadTextPreviews() {
|
| 196 |
+
// Only attempt after files are loaded and user is known
|
| 197 |
+
if (!currentUser || !currentPassword || !Array.isArray(files)) return;
|
| 198 |
+
for (const file of files) {
|
| 199 |
+
// Simple heuristic: only fetch preview for obvious text formats
|
| 200 |
+
const name = (file && file.name) ? String(file.name).toLowerCase() : '';
|
| 201 |
+
if (!name.endsWith('.txt') && !name.endsWith('.md')) continue;
|
| 202 |
+
try {
|
| 203 |
+
const result = await callSecureApi("/get_preview_text_action", withTokens({
|
| 204 |
+
user_id: currentUser,
|
| 205 |
+
password: currentPassword,
|
| 206 |
+
filename: file.name,
|
| 207 |
+
}));
|
| 208 |
+
const text = Array.isArray(result.data) ? result.data[0] : result.data;
|
| 209 |
+
if (typeof text === 'string' && text.trim()) {
|
| 210 |
+
file.preview = text;
|
| 211 |
+
}
|
| 212 |
+
} catch (err) {
|
| 213 |
+
console.error('Text preview preload error for', file.name, err);
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
render(files);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
// Update stats cards
|
| 220 |
function updateStatsCards() {
|
| 221 |
const cards = document.querySelectorAll('.card');
|
|
|
|
| 260 |
}
|
| 261 |
|
| 262 |
// Grid HTML
|
| 263 |
+
const gridHTML = list.map((f, i) => {
|
| 264 |
+
let iconOrPreview = f.icon;
|
| 265 |
+
if (f.preview && typeof f.preview === 'string' && f.preview.trim()) {
|
| 266 |
+
const words = f.preview.trim().split(/\s+/).slice(0, 5).join(' ');
|
| 267 |
+
const snippet = words + (f.preview.trim().length > words.length ? '...' : '');
|
| 268 |
+
iconOrPreview = escapeHtml(snippet);
|
| 269 |
+
}
|
| 270 |
+
return `
|
| 271 |
+
<div class="file-card ${selected.has(i) ? 'selected' : ''}" onclick="toggleSelect(${i})" ondblclick="openPreview(${i})">
|
| 272 |
<span class="fc-check"><i class="fa-solid fa-check"></i></span>
|
| 273 |
+
<span class="fc-icon">${iconOrPreview}</span>
|
| 274 |
<span class="fc-name">${f.name}</span>
|
| 275 |
<span class="fc-meta">${f.size}</span>
|
| 276 |
</div>
|
| 277 |
+
`;
|
| 278 |
+
}).join('');
|
| 279 |
|
| 280 |
grid.innerHTML = gridHTML;
|
| 281 |
console.log('Grid rendered with', list.length, 'items');
|