issue
Browse files- image/javascript/image.js +39 -3
image/javascript/image.js
CHANGED
|
@@ -182,10 +182,16 @@ function updateUI() {
|
|
| 182 |
function renderFileCards() {
|
| 183 |
const filesGrid = document.getElementById('files-grid');
|
| 184 |
|
| 185 |
-
filesGrid.innerHTML = selectedFiles.map(file =>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
<div class="file-card" id="file-${file.id}">
|
| 187 |
<button class="remove-button" onclick="removeFile('${file.id}')">×</button>
|
| 188 |
${window.location.pathname == '/image/remove_metadata' && file.other_info ? `<button class="remove-button" style="top: 40px; background: #17a2b8;" onclick="showMetadata('${file.id}')">i</button>` : ``}
|
|
|
|
|
|
|
| 189 |
|
| 190 |
<div class="file-preview">
|
| 191 |
${file.preview ? `<img src="${file.preview}" alt="${file.name}">` : '<span class="file-icon">🖼️</span>'}
|
|
@@ -196,12 +202,13 @@ function renderFileCards() {
|
|
| 196 |
<p>${file.size}</p>
|
| 197 |
|
| 198 |
<div class="file-status">
|
| 199 |
-
<div class="status-indicator ${file.status === 'processing' ? 'processing' : file.status === 'error' ? 'error' : ''}"></div>
|
| 200 |
<span>${getStatusText(file.status)}</span>
|
| 201 |
</div>
|
| 202 |
</div>
|
| 203 |
</div>
|
| 204 |
-
|
|
|
|
| 205 |
}
|
| 206 |
|
| 207 |
function updateFileCard(fileId) {
|
|
@@ -253,6 +260,7 @@ async function processButtonFn() {
|
|
| 253 |
} catch (error) {
|
| 254 |
console.error('Processing error:', error);
|
| 255 |
file.status = 'error';
|
|
|
|
| 256 |
showMessage(`Error processing ${file.name}: ${error.message}`, 'error');
|
| 257 |
}
|
| 258 |
|
|
@@ -431,3 +439,31 @@ function closeMetadataModal() {
|
|
| 431 |
document.getElementById('metadata-modal').style.display = 'none';
|
| 432 |
document.getElementById('modal-backdrop').style.display = 'none';
|
| 433 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
function renderFileCards() {
|
| 183 |
const filesGrid = document.getElementById('files-grid');
|
| 184 |
|
| 185 |
+
filesGrid.innerHTML = selectedFiles.map(file => {
|
| 186 |
+
// Find completed file data for download URL
|
| 187 |
+
const completedFile = completedFiles.find(cf => cf.id === file.id);
|
| 188 |
+
|
| 189 |
+
return `
|
| 190 |
<div class="file-card" id="file-${file.id}">
|
| 191 |
<button class="remove-button" onclick="removeFile('${file.id}')">×</button>
|
| 192 |
${window.location.pathname == '/image/remove_metadata' && file.other_info ? `<button class="remove-button" style="top: 40px; background: #17a2b8;" onclick="showMetadata('${file.id}')">i</button>` : ``}
|
| 193 |
+
${file.status === 'error' && file.errorMessage ? `<button class="remove-button" style="top: 40px; background: #dc3545;" onclick="showError('${file.id}')" title="View error">!</button>` : ``}
|
| 194 |
+
${file.status === 'completed' && completedFile ? `<button class="remove-button" style="top: ${file.other_info ? '70px' : '40px'}; background: #28a745;" onclick="downloadFile('${file.id}')" title="Download">⬇</button>` : ``}
|
| 195 |
|
| 196 |
<div class="file-preview">
|
| 197 |
${file.preview ? `<img src="${file.preview}" alt="${file.name}">` : '<span class="file-icon">🖼️</span>'}
|
|
|
|
| 202 |
<p>${file.size}</p>
|
| 203 |
|
| 204 |
<div class="file-status">
|
| 205 |
+
<div class="status-indicator ${file.status === 'processing' ? 'processing' : file.status === 'error' ? 'error' : file.status === 'completed' ? 'completed' : ''}"></div>
|
| 206 |
<span>${getStatusText(file.status)}</span>
|
| 207 |
</div>
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
+
`;
|
| 211 |
+
}).join('');
|
| 212 |
}
|
| 213 |
|
| 214 |
function updateFileCard(fileId) {
|
|
|
|
| 260 |
} catch (error) {
|
| 261 |
console.error('Processing error:', error);
|
| 262 |
file.status = 'error';
|
| 263 |
+
file.errorMessage = error.message;
|
| 264 |
showMessage(`Error processing ${file.name}: ${error.message}`, 'error');
|
| 265 |
}
|
| 266 |
|
|
|
|
| 439 |
document.getElementById('metadata-modal').style.display = 'none';
|
| 440 |
document.getElementById('modal-backdrop').style.display = 'none';
|
| 441 |
}
|
| 442 |
+
|
| 443 |
+
/**
|
| 444 |
+
* Show error message for a file in a modal/alert
|
| 445 |
+
*/
|
| 446 |
+
function showError(fileId) {
|
| 447 |
+
const file = selectedFiles.find(f => f.id === fileId);
|
| 448 |
+
if (file && file.errorMessage) {
|
| 449 |
+
alert(`Error processing ${file.name}:\n\n${file.errorMessage}`);
|
| 450 |
+
} else {
|
| 451 |
+
alert('Unknown error occurred');
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
/**
|
| 456 |
+
* Download a single processed file
|
| 457 |
+
*/
|
| 458 |
+
function downloadFile(fileId) {
|
| 459 |
+
const completedFile = completedFiles.find(f => f.id === fileId);
|
| 460 |
+
if (completedFile) {
|
| 461 |
+
const link = document.createElement('a');
|
| 462 |
+
link.href = completedFile.url;
|
| 463 |
+
link.download = completedFile.processedName;
|
| 464 |
+
link.target = '_blank';
|
| 465 |
+
document.body.appendChild(link);
|
| 466 |
+
link.click();
|
| 467 |
+
document.body.removeChild(link);
|
| 468 |
+
}
|
| 469 |
+
}
|