theguywhosucks commited on
Commit
a7f712b
·
verified ·
1 Parent(s): ab9086c

Upload 17 files

Browse files
Files changed (1) hide show
  1. 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/Blob is accepted by the client as `filepath`
 
481
  try {
482
  loading(true);
483
- // Prepare token options robustly for different client versions
484
- const token = getWriteToken() || getReadToken() || '';
485
- const opts = token ? { hf_token: token, token } : {};
486
- // Lazily connect the client (pass an options object even if empty to avoid version quirks)
487
- if (!client) {
488
- client = await Client.connect("pockit-cloud/main", opts);
489
- }
490
- // Connect exactly as per docs; only pass token if present
491
- const token = getWriteToken() || getReadToken() || '';
492
  if (!client) {
493
- client = token
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
- console.log('Uploaded:', file.name);
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);