From: Sergey Matveev Date: Thu, 4 May 2023 08:25:59 +0000 (+0300) Subject: Include torrent links from Metalink4 X-Git-Url: http://www.git.stargrave.org/?p=godlighty.git;a=commitdiff_plain;h=e5b6a66ac9e02d1369f72bc2b1b3fac3de36ef22 Include torrent links from Metalink4 --- diff --git a/handler.go b/handler.go index 44c8a1f..81bd2aa 100644 --- a/handler.go +++ b/handler.go @@ -273,6 +273,9 @@ IndexLookuped: for name, digest := range forHTTP.Hashes { w.Header().Add("Digest", name+"="+base64.StdEncoding.EncodeToString(digest)) } + for _, u := range forHTTP.Torrents { + w.Header().Add("Link", "<"+u+`>; rel=describedby; type="application/x-bittorrent"`) + } } SkipMeta4: diff --git a/meta4/parse.go b/meta4/parse.go index 7659bc8..0c598d3 100644 --- a/meta4/parse.go +++ b/meta4/parse.go @@ -37,6 +37,7 @@ var KnownHashes = map[string]string{ type ForHTTP struct { Hashes map[string][]byte URLs []string + Torrents []string } func Parse(fn string, data []byte) (*ForHTTP, error) { @@ -64,6 +65,11 @@ func Parse(fn string, data []byte) (*ForHTTP, error) { for _, u := range f.URLs { forHTTP.URLs = append(forHTTP.URLs, u.URL) } + for _, m := range f.MetaURLs { + if m.MediaType == "torrent" { + forHTTP.Torrents = append(forHTTP.Torrents, m.URL) + } + } return &forHTTP, nil } return nil, nil