theguywhosucks commited on
Commit
da8cca5
·
verified ·
1 Parent(s): d63df2f

Upload 17 files

Browse files
Files changed (2) hide show
  1. dashboardlogic.js +13 -13
  2. server.js +21 -0
dashboardlogic.js CHANGED
@@ -421,20 +421,20 @@ async function downloadFile(id) {
421
  const file = files[id];
422
  try {
423
  loading(true);
424
- // Use /get_download_link_action to get the raw download link
425
- const result = await callSecureApi("/get_download_link_action", withTokens({
426
- user_id: currentUser,
427
- password: currentPassword,
428
- filename: file.name,
429
- }));
430
- const fileUrl = Array.isArray(result.data) ? result.data[0] : result.data;
 
 
 
 
 
431
  if (typeof fileUrl === 'string' && (fileUrl.startsWith('http') || fileUrl.startsWith('https'))) {
432
- // Fetch as blob to force download, with optional Hugging Face token
433
- const hfToken = sessionStorage.getItem('hf_read_token');
434
- const fetchOptions = hfToken ? {
435
- headers: { 'Authorization': 'Bearer ' + hfToken }
436
- } : {};
437
- const response = await fetch(fileUrl, fetchOptions);
438
  if (!response.ok) {
439
  console.error('Download fetch error:', {
440
  url: fileUrl,
 
421
  const file = files[id];
422
  try {
423
  loading(true);
424
+ const resp = await fetch('/api/download-link', {
425
+ method: 'POST',
426
+ headers: { 'Content-Type': 'application/json' },
427
+ body: JSON.stringify({
428
+ user_id: currentUser,
429
+ password: currentPassword,
430
+ filename: file.name,
431
+ }),
432
+ });
433
+ if (!resp.ok) throw new Error('Download-link HTTP ' + resp.status);
434
+ const payload = await resp.json();
435
+ const fileUrl = Array.isArray(payload.data) ? payload.data[0] : payload.data;
436
  if (typeof fileUrl === 'string' && (fileUrl.startsWith('http') || fileUrl.startsWith('https'))) {
437
+ const response = await fetch(fileUrl);
 
 
 
 
 
438
  if (!response.ok) {
439
  console.error('Download fetch error:', {
440
  url: fileUrl,
server.js CHANGED
@@ -94,6 +94,27 @@ app.post("/api/upload", upload.single("file"), async (req, res) => {
94
  }
95
  });
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  app.use(express.static("."));
98
 
99
  app.listen(PORT, () => {
 
94
  }
95
  });
96
 
97
+ app.post("/api/download-link", async (req, res) => {
98
+ const { user_id, password, filename } = req.body || {};
99
+
100
+ if (!user_id || !password || !filename) {
101
+ return res.status(400).json({ error: "Missing user_id, password, or filename" });
102
+ }
103
+
104
+ try {
105
+ const client = await clientPromise;
106
+ const result = await client.predict("/get_download_link_action", {
107
+ user_id,
108
+ password,
109
+ filename,
110
+ });
111
+ res.json({ data: result.data });
112
+ } catch (err) {
113
+ console.error("Download-link error:", err);
114
+ res.status(500).json({ error: "Download link failed", details: err.message });
115
+ }
116
+ });
117
+
118
  app.use(express.static("."));
119
 
120
  app.listen(PORT, () => {