Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- dashboardlogic.js +15 -15
dashboardlogic.js
CHANGED
|
@@ -477,43 +477,43 @@ async function downloadPreviewFile() {
|
|
| 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
|
|
|
|
| 481 |
try {
|
| 482 |
loading(true);
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
const
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
}
|
| 490 |
-
// Connect exactly as per docs; only pass token if present
|
| 491 |
-
const token = getWriteToken() || getReadToken() || '';
|
| 492 |
if (!client) {
|
| 493 |
-
client =
|
| 494 |
-
? await Client.connect("pockit-cloud/main", { hf_token: token })
|
| 495 |
-
: await Client.connect("pockit-cloud/main");
|
| 496 |
}
|
|
|
|
|
|
|
| 497 |
const result = await client.predict("/upload_file_secure", {
|
| 498 |
user_id: currentUser,
|
| 499 |
password: currentPassword,
|
| 500 |
filepath: file,
|
| 501 |
custom_name: file.name,
|
| 502 |
});
|
|
|
|
| 503 |
console.debug('Upload response:', result);
|
| 504 |
-
|
| 505 |
// Update storage
|
| 506 |
const [status, capacityUsed, usedTotal] = result.data;
|
| 507 |
const percent = Math.round(capacityUsed);
|
| 508 |
document.querySelector('.card-bar-fill').style.width = percent + '%';
|
| 509 |
document.querySelector('.sbar-fill').style.width = percent + '%';
|
| 510 |
document.querySelector('.stor-label span:last-child').textContent = usedTotal;
|
|
|
|
| 511 |
// Reload files
|
| 512 |
await loadFiles();
|
| 513 |
showToast(file.name + ' uploaded');
|
| 514 |
input.value = '';
|
| 515 |
} catch (err) {
|
| 516 |
-
try { console.error('Upload error (detailed):', err?.message || err, err); } catch(_) {}
|
| 517 |
showToast('Upload failed');
|
| 518 |
} finally {
|
| 519 |
loading(false);
|
|
|
|
| 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 |
+
// Private Space: pass Hugging Face token when connecting (stored as "hf_server_token" via login)
|
| 486 |
+
const hfToken = getWriteToken() || getReadToken();
|
| 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 |
+
try { console.error('Upload error (detailed):', err?.message || err, err); } catch (_) {}
|
| 517 |
showToast('Upload failed');
|
| 518 |
} finally {
|
| 519 |
loading(false);
|