diff --git a/internal/web/index.html b/internal/web/index.html
index 4b0369a..294de11 100644
--- a/internal/web/index.html
+++ b/internal/web/index.html
@@ -1621,10 +1621,11 @@
}
const baseUrl = window.location.origin;
+ const magnetHash = file.torrent_info?.InfoHash || hash;
const links = {
direct: `${baseUrl}/api/download/${hash}`,
torrent: `${baseUrl}/api/torrent/${hash}`,
- magnet: `magnet:?xt=urn:btih:${hash}&dn=${encodeURIComponent(file.name)}`,
+ magnet: `magnet:?xt=urn:btih:${magnetHash}&dn=${encodeURIComponent(file.name)}`,
stream: file.name.match(/\.(mp4|mkv|avi|mov)$/i) ? `${baseUrl}/api/stream/${hash}` : null
};
diff --git a/internal/web/static/upload.js b/internal/web/static/upload.js
index ee06e1e..3074eef 100644
--- a/internal/web/static/upload.js
+++ b/internal/web/static/upload.js
@@ -613,10 +613,20 @@ class GatewayUI {
}
const baseUrl = window.location.origin;
+
+ // Use torrent info hash for magnet link if available, otherwise use file hash
+ let magnetHash = hash;
+ if (fileData && fileData.torrent_info && fileData.torrent_info.InfoHash) {
+ magnetHash = fileData.torrent_info.InfoHash;
+ console.log('Using torrent InfoHash for magnet:', magnetHash);
+ } else {
+ console.log('No torrent InfoHash found, using file hash:', magnetHash);
+ }
+
const links = {
direct: `${baseUrl}/api/download/${hash}`,
torrent: `${baseUrl}/api/torrent/${hash}`,
- magnet: `magnet:?xt=urn:btih:${hash}&dn=${encodeURIComponent(name)}`
+ magnet: `magnet:?xt=urn:btih:${magnetHash}&dn=${encodeURIComponent(name)}`
};
// Add streaming links if available
@@ -628,7 +638,7 @@ class GatewayUI {
this.showShareModal(name, links);
} catch (error) {
console.error('Failed to get file metadata:', error);
- // Fallback to basic links
+ // Fallback to basic links (using file hash for magnet since we can't get torrent info)
const baseUrl = window.location.origin;
const links = {
direct: `${baseUrl}/api/download/${hash}`,