Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- dashboardlogic.js +18 -16
dashboardlogic.js
CHANGED
|
@@ -474,24 +474,25 @@ async function downloadPreviewFile() {
|
|
| 474 |
}
|
| 475 |
}
|
| 476 |
|
| 477 |
-
// Upload file
|
| 478 |
async function handleUpload(input) {
|
| 479 |
-
if (!input.files || !input.files[0]) return;
|
|
|
|
| 480 |
try {
|
| 481 |
loading(true);
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
console.log('Uploaded:', file.name);
|
| 496 |
// Update storage
|
| 497 |
const [status, capacityUsed, usedTotal] = result.data;
|
|
@@ -505,8 +506,9 @@ async function handleUpload(input) {
|
|
| 505 |
input.value = '';
|
| 506 |
} catch (err) {
|
| 507 |
console.error('Upload error:', err);
|
| 508 |
-
loading(false);
|
| 509 |
showToast('Upload failed');
|
|
|
|
|
|
|
| 510 |
}
|
| 511 |
}
|
| 512 |
|
|
|
|
| 474 |
}
|
| 475 |
}
|
| 476 |
|
| 477 |
+
// Upload file (single file) via server-side endpoint so private HF token stays on the server
|
| 478 |
async function handleUpload(input) {
|
| 479 |
+
if (!input.files || !input.files[0]) return;
|
| 480 |
+
const file = input.files[0];
|
| 481 |
try {
|
| 482 |
loading(true);
|
| 483 |
+
const formData = new FormData();
|
| 484 |
+
formData.append('file', file);
|
| 485 |
+
formData.append('user_id', currentUser);
|
| 486 |
+
formData.append('password', currentPassword);
|
| 487 |
+
formData.append('custom_name', file.name);
|
| 488 |
+
|
| 489 |
+
const resp = await fetch('/api/upload', {
|
| 490 |
+
method: 'POST',
|
| 491 |
+
body: formData,
|
| 492 |
+
});
|
| 493 |
+
if (!resp.ok) throw new Error('Upload HTTP ' + resp.status);
|
| 494 |
+
const result = await resp.json();
|
| 495 |
+
|
| 496 |
console.log('Uploaded:', file.name);
|
| 497 |
// Update storage
|
| 498 |
const [status, capacityUsed, usedTotal] = result.data;
|
|
|
|
| 506 |
input.value = '';
|
| 507 |
} catch (err) {
|
| 508 |
console.error('Upload error:', err);
|
|
|
|
| 509 |
showToast('Upload failed');
|
| 510 |
+
} finally {
|
| 511 |
+
loading(false);
|
| 512 |
}
|
| 513 |
}
|
| 514 |
|