add magnet export

This commit is contained in:
YouROK
2021-05-31 09:34:24 +03:00
parent 615f0b8f81
commit 21d98d0e2e

View File

@@ -1,7 +1,10 @@
package pages package pages
import ( import (
"github.com/anacrolix/torrent/metainfo"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"server/settings"
"server/torr" "server/torr"
"server/web/pages/template" "server/web/pages/template"
) )
@@ -9,6 +12,7 @@ import (
func SetupRoute(route *gin.RouterGroup) { func SetupRoute(route *gin.RouterGroup) {
route.GET("/", mainPage) route.GET("/", mainPage)
route.GET("/stat", statPage) route.GET("/stat", statPage)
route.GET("/magnets", getTorrents)
} }
func mainPage(c *gin.Context) { func mainPage(c *gin.Context) {
@@ -19,3 +23,18 @@ func statPage(c *gin.Context) {
torr.WriteStatus(c.Writer) torr.WriteStatus(c.Writer)
c.Status(200) c.Status(200)
} }
func getTorrents(c *gin.Context) {
list := settings.ListTorrent()
http := "<div>"
for _, db := range list {
ts := db.TorrentSpec
mi := metainfo.MetaInfo{
AnnounceList: ts.Trackers,
}
mag := mi.Magnet(ts.DisplayName, ts.InfoHash)
http += "<p><a href='" + mag.String() + "'>magnet:?xt=urn:btih:" + mag.InfoHash.HexString() + "</a></p>"
}
http += "</div>"
c.Data(200, "text/html; charset=utf-8", []byte(http))
}