Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- dashboardlogic.js +8 -23
dashboardlogic.js
CHANGED
|
@@ -476,47 +476,32 @@ async function downloadPreviewFile() {
|
|
| 476 |
|
| 477 |
// Upload file using Gradio JS client to /upload_file_secure
|
| 478 |
async function handleUpload(input) {
|
| 479 |
-
if (!input.files || !input.files[0]) return;
|
| 480 |
-
const file = input.files[0]; // File is a Blob and can be sent directly as `filepath`
|
| 481 |
-
|
| 482 |
try {
|
| 483 |
loading(true);
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
const
|
| 487 |
-
if (!hfToken) throw new Error('Missing Hugging Face token');
|
| 488 |
-
|
| 489 |
-
// Connect once and reuse
|
| 490 |
-
if (!client) {
|
| 491 |
-
client = await Client.connect("pockit-cloud/main", { hf_token: hfToken });
|
| 492 |
-
}
|
| 493 |
-
|
| 494 |
-
// Follow docs exactly: predict with {user_id, password, filepath, custom_name}
|
| 495 |
-
const result = await client.predict("/upload_file_secure", {
|
| 496 |
user_id: currentUser,
|
| 497 |
password: currentPassword,
|
| 498 |
filepath: file,
|
| 499 |
custom_name: file.name,
|
| 500 |
-
});
|
| 501 |
-
|
| 502 |
-
console.debug('Upload response:', result);
|
| 503 |
-
|
| 504 |
// Update storage
|
| 505 |
const [status, capacityUsed, usedTotal] = result.data;
|
| 506 |
const percent = Math.round(capacityUsed);
|
| 507 |
document.querySelector('.card-bar-fill').style.width = percent + '%';
|
| 508 |
document.querySelector('.sbar-fill').style.width = percent + '%';
|
| 509 |
document.querySelector('.stor-label span:last-child').textContent = usedTotal;
|
| 510 |
-
|
| 511 |
// Reload files
|
| 512 |
await loadFiles();
|
| 513 |
showToast(file.name + ' uploaded');
|
| 514 |
input.value = '';
|
| 515 |
} catch (err) {
|
| 516 |
-
|
| 517 |
-
showToast('Upload failed');
|
| 518 |
-
} finally {
|
| 519 |
loading(false);
|
|
|
|
| 520 |
}
|
| 521 |
}
|
| 522 |
|
|
|
|
| 476 |
|
| 477 |
// Upload file using Gradio JS client to /upload_file_secure
|
| 478 |
async function handleUpload(input) {
|
| 479 |
+
if (!input.files || !input.files[0]) return; const file = input.files[0];
|
|
|
|
|
|
|
| 480 |
try {
|
| 481 |
loading(true);
|
| 482 |
+
// Match known-working version: rely on existing connected client and pass tokens with the request
|
| 483 |
+
console.log('Uploading file:', file, 'type:', file.constructor.name);
|
| 484 |
+
const result = await client.predict("/upload_file_secure", withTokens({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
user_id: currentUser,
|
| 486 |
password: currentPassword,
|
| 487 |
filepath: file,
|
| 488 |
custom_name: file.name,
|
| 489 |
+
}));
|
| 490 |
+
console.log('Uploaded:', file.name);
|
|
|
|
|
|
|
| 491 |
// Update storage
|
| 492 |
const [status, capacityUsed, usedTotal] = result.data;
|
| 493 |
const percent = Math.round(capacityUsed);
|
| 494 |
document.querySelector('.card-bar-fill').style.width = percent + '%';
|
| 495 |
document.querySelector('.sbar-fill').style.width = percent + '%';
|
| 496 |
document.querySelector('.stor-label span:last-child').textContent = usedTotal;
|
|
|
|
| 497 |
// Reload files
|
| 498 |
await loadFiles();
|
| 499 |
showToast(file.name + ' uploaded');
|
| 500 |
input.value = '';
|
| 501 |
} catch (err) {
|
| 502 |
+
console.error('Upload error:', err);
|
|
|
|
|
|
|
| 503 |
loading(false);
|
| 504 |
+
showToast('Upload failed');
|
| 505 |
}
|
| 506 |
}
|
| 507 |
|