From 22db45c40da19aef9f559e1ecd03397ed1d0c258 Mon Sep 17 00:00:00 2001 From: Tohru <65994850+Tohrusky@users.noreply.github.com> Date: Thu, 18 Jul 2024 02:02:06 +0800 Subject: [PATCH] fix: Torrent AnnounceList Type: [][]string (#23) --- module/torrent/torrent.go | 6 +++++- module/torrent/torrent_test.go | 1 - module/torrent/type.go | 10 +++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/module/torrent/torrent.go b/module/torrent/torrent.go index d6c3629..9d72ad1 100644 --- a/module/torrent/torrent.go +++ b/module/torrent/torrent.go @@ -64,7 +64,11 @@ func (bencodeTorrent *BitTorrentFile) Repack(editStrategy *BitTorrentFileEditStr bencodeTorrent.Announce = editStrategy.Announce } if editStrategy.AnnounceList != nil { - bencodeTorrent.AnnounceList = editStrategy.AnnounceList + var announceList [][]string + for _, announce := range editStrategy.AnnounceList { + announceList = append(announceList, []string{announce}) + } + bencodeTorrent.AnnounceList = announceList } if editStrategy.Comment != "" { bencodeTorrent.Comment = editStrategy.Comment diff --git a/module/torrent/torrent_test.go b/module/torrent/torrent_test.go index 7b6674c..1aef0c6 100644 --- a/module/torrent/torrent_test.go +++ b/module/torrent/torrent_test.go @@ -71,7 +71,6 @@ func TestRepackTorrent(t *testing.T) { t.Log(torrent) assert.Equal(t, torrent.Comment, comment) assert.Equal(t, torrent.Info.Source, infoSource) - assert.Equal(t, torrent.AnnounceList, TRACKER_LIST) } func TestTorrentFileList(t *testing.T) { diff --git a/module/torrent/type.go b/module/torrent/type.go index dfc16df..757739c 100644 --- a/module/torrent/type.go +++ b/module/torrent/type.go @@ -1,11 +1,11 @@ package torrent type BitTorrentFile struct { - Announce string `bencode:"announce"` - AnnounceList []string `bencode:"announce-list,omitempty"` - CreationDate int64 `bencode:"creation date,omitempty"` - Comment string `bencode:"comment,omitempty"` - CreatedBy string `bencode:"created by,omitempty"` + Announce string `bencode:"announce"` + AnnounceList [][]string `bencode:"announce-list,omitempty"` + CreationDate int64 `bencode:"creation date,omitempty"` + Comment string `bencode:"comment,omitempty"` + CreatedBy string `bencode:"created by,omitempty"` Info struct { Files []struct { Path []string `bencode:"path"`