theguywhosucks commited on
Commit
f7fe3bc
·
verified ·
1 Parent(s): 74b5a6f

Upload 17 files

Browse files
Files changed (1) hide show
  1. dashboardlogic.js +18 -16
dashboardlogic.js CHANGED
@@ -474,24 +474,25 @@ async function downloadPreviewFile() {
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; 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
- // Ensure client is connected with HF token for private Space (token set by login as hf_server_token)
485
- if (!client) {
486
- const hfToken = getWriteToken() || getReadToken();
487
- client = await Client.connect("pockit-cloud/main", { hf_token: hfToken });
488
- }
489
- const result = await client.predict("/upload_file_secure", withTokens({
490
- user_id: currentUser,
491
- password: currentPassword,
492
- filepath: file,
493
- custom_name: file.name,
494
- }));
495
  console.log('Uploaded:', file.name);
496
  // Update storage
497
  const [status, capacityUsed, usedTotal] = result.data;
@@ -505,8 +506,9 @@ async function handleUpload(input) {
505
  input.value = '';
506
  } catch (err) {
507
  console.error('Upload error:', err);
508
- loading(false);
509
  showToast('Upload failed');
 
 
510
  }
511
  }
512
 
 
474
  }
475
  }
476
 
477
+ // Upload file (single file) via server-side endpoint so private HF token stays on the server
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
+
489
+ const resp = await fetch('/api/upload', {
490
+ method: 'POST',
491
+ body: formData,
492
+ });
493
+ if (!resp.ok) throw new Error('Upload HTTP ' + resp.status);
494
+ const result = await resp.json();
495
+
496
  console.log('Uploaded:', file.name);
497
  // Update storage
498
  const [status, capacityUsed, usedTotal] = result.data;
 
506
  input.value = '';
507
  } catch (err) {
508
  console.error('Upload error:', err);
 
509
  showToast('Upload failed');
510
+ } finally {
511
+ loading(false);
512
  }
513
  }
514