]> Sergey Matveev's repositories - godlighty.git/commitdiff
Include torrent links from Metalink4
authorSergey Matveev <stargrave@stargrave.org>
Thu, 4 May 2023 08:25:59 +0000 (11:25 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 4 May 2023 08:26:57 +0000 (11:26 +0300)
handler.go
meta4/parse.go

index 44c8a1fb40886d7aaf731ed7aeb062280f1a2fbf..81bd2aa1f399101d5a10ef06619ea80cd845c9f5 100644 (file)
@@ -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:
 
index 7659bc88a4841203076a7dfb33e8722638ea3fc7..0c598d31befcfe08b08bfd3d13c0d4ccc6194a71 100644 (file)
@@ -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