Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- dashboardlogic.js +14 -12
dashboardlogic.js
CHANGED
|
@@ -474,22 +474,23 @@ async function downloadPreviewFile() {
|
|
| 474 |
}
|
| 475 |
}
|
| 476 |
|
| 477 |
-
// Upload file
|
| 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 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
const
|
| 489 |
-
|
| 490 |
-
|
|
|
|
|
|
|
| 491 |
});
|
| 492 |
-
const result = await resp.json();
|
| 493 |
console.log('Uploaded:', file.name);
|
| 494 |
// Update storage
|
| 495 |
const [status, capacityUsed, usedTotal] = result.data;
|
|
@@ -503,8 +504,9 @@ async function handleUpload(input) {
|
|
| 503 |
input.value = '';
|
| 504 |
} catch (err) {
|
| 505 |
console.error('Upload error:', err);
|
| 506 |
-
loading(false);
|
| 507 |
showToast('Upload failed');
|
|
|
|
|
|
|
| 508 |
}
|
| 509 |
}
|
| 510 |
|
|
|
|
| 474 |
}
|
| 475 |
}
|
| 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/Blob is accepted by the client as `filepath`
|
| 481 |
try {
|
| 482 |
loading(true);
|
| 483 |
+
// Lazily connect the client; include HF token if this Space is private
|
| 484 |
+
if (!client) {
|
| 485 |
+
const token = getWriteToken() || getReadToken() || undefined;
|
| 486 |
+
client = await Client.connect("pockit-cloud/main", token ? { hf_token: token } : undefined);
|
| 487 |
+
}
|
| 488 |
+
const result = await client.predict("/upload_file_secure", {
|
| 489 |
+
user_id: currentUser,
|
| 490 |
+
password: currentPassword,
|
| 491 |
+
filepath: file,
|
| 492 |
+
custom_name: file.name,
|
| 493 |
});
|
|
|
|
| 494 |
console.log('Uploaded:', file.name);
|
| 495 |
// Update storage
|
| 496 |
const [status, capacityUsed, usedTotal] = result.data;
|
|
|
|
| 504 |
input.value = '';
|
| 505 |
} catch (err) {
|
| 506 |
console.error('Upload error:', err);
|
|
|
|
| 507 |
showToast('Upload failed');
|
| 508 |
+
} finally {
|
| 509 |
+
loading(false);
|
| 510 |
}
|
| 511 |
}
|
| 512 |
|