theguywhosucks commited on
Commit
bb7c19c
·
verified ·
1 Parent(s): c71b0e8

Upload 17 files

Browse files
Files changed (1) hide show
  1. dashboardlogic.js +14 -12
dashboardlogic.js CHANGED
@@ -474,22 +474,23 @@ async function downloadPreviewFile() {
474
  }
475
  }
476
 
477
- // Upload file - use proxy endpoint for upload
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
- const resp = await fetch('/api/upload', {
489
- method: 'POST',
490
- body: formData
 
 
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