diff --git a/public/index.html b/public/index.html
index 3e181bc..74b6d28 100644
--- a/public/index.html
+++ b/public/index.html
@@ -374,7 +374,7 @@
tr.appendChild(tdStatus);
const tdActions = document.createElement("td");
- // Existing Pause/Resume button
+ // Pause/Resume button
const toggleBtn = document.createElement("button");
toggleBtn.className = "btn btn-warning btn-sm me-2";
if (torrent.paused) {
@@ -394,7 +394,7 @@
}
tdActions.appendChild(toggleBtn);
- // Existing Remove button
+ // Remove button
const removeBtn = document.createElement("button");
removeBtn.textContent = "Remove";
removeBtn.className = "btn btn-danger btn-sm me-2";
@@ -406,7 +406,7 @@
};
tdActions.appendChild(removeBtn);
- // New Copy Magnet button
+ // Copy Magnet button
const copyMagnetBtn = document.createElement("button");
copyMagnetBtn.textContent = "Copy Magnet";
copyMagnetBtn.className = "btn btn-secondary btn-sm me-2";
@@ -425,6 +425,15 @@
};
tdActions.appendChild(copyMagnetBtn);
+ // New Download button
+ const downloadBtn = document.createElement("button");
+ downloadBtn.textContent = "Download";
+ downloadBtn.className = "btn btn-primary btn-sm";
+ downloadBtn.onclick = () => {
+ window.location.href = `/download/${torrent.infoHash}`;
+ };
+ tdActions.appendChild(downloadBtn);
+
tr.appendChild(tdActions);
list.appendChild(tr);
});
diff --git a/server.js b/server.js
index 138826d..6c55255 100644
--- a/server.js
+++ b/server.js
@@ -262,6 +262,25 @@ app.get("/torrents", (req, res) => {
}
});
+// Add after existing routes in server.js
+app.get("/download/:infoHash", async (req, res) => {
+ const infoHash = req.params.infoHash;
+ const savedData = savedTorrents.find((t) => t.infoHash === infoHash);
+ if (!savedData) {
+ return res.status(404).json({ error: "Torrent not found" });
+ }
+ const filePath = path.join(STORAGE_DIR, savedData.name);
+ if (!(await pathExists(filePath))) {
+ return res.status(404).json({ error: "File not found" });
+ }
+ res.download(filePath, savedData.name, (err) => {
+ if (err) {
+ logger.error("Error downloading file: " + err);
+ res.status(500).json({ error: "Error downloading file" });
+ }
+ });
+});
+
// Pause a torrent
app.post("/pause/:infoHash", async (req, res) => {
const infoHash = req.params.infoHash;