feat: self calculate required torrent hash

This commit is contained in:
Simon Ding
2024-10-10 09:01:51 +08:00
parent 37ad1391db
commit 19f21ddd6e
5 changed files with 47 additions and 77 deletions

View File

@@ -11,7 +11,6 @@ import (
"polaris/pkg/utils"
"strconv"
"github.com/anacrolix/torrent/metainfo"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
@@ -123,21 +122,9 @@ func (s *Server) addTorrent2Blacklist(link string) error {
if link == "" {
return nil
}
if mi, err := metainfo.ParseMagnetV2Uri(link); err != nil {
return errors.Errorf("magnet link is not valid: %v", err)
if hash, err := utils.MagnetHash(link); err != nil {
return err
} else {
hash := ""
if mi.InfoHash.Unwrap().HexString() != "" {
hash = mi.InfoHash.Unwrap().HexString()
} else {
btmh := mi.V2InfoHash.Unwrap()
if btmh.HexString() != "" {
hash = btmh.HexString()
}
}
if hash == "" {
return errors.Errorf("magnet has no info hash: %v", link)
}
item := ent.Blacklist{
Type: blacklist.TypeTorrent,
Value: schema.BlacklistValue{