Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- dashboardlogic.js +13 -13
- 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 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
if (typeof fileUrl === 'string' && (fileUrl.startsWith('http') || fileUrl.startsWith('https'))) {
|
| 432 |
-
|
| 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, () => {
|