fix(announce): parse torrentUrl (#557)

fix(announce): generate torrentUrl
This commit is contained in:
ze0s 2022-12-03 21:20:06 +01:00 committed by GitHub
parent 4623921cbb
commit 6ad4abe296
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 3 deletions

View file

@ -209,7 +209,8 @@ func (p *IndexerIRCParse) ParseMatch(baseURL string, vars map[string]string) (*I
return nil, errors.New("could not write torrent url template output")
}
parsedUrl, err := url.Parse(urlBytes.String())
templateUrl := urlBytes.String()
parsedUrl, err := url.Parse(templateUrl)
if err != nil {
return nil, err
}
@ -223,12 +224,16 @@ func (p *IndexerIRCParse) ParseMatch(baseURL string, vars map[string]string) (*I
}
// join baseURL with query
torrentURL, err := url.JoinPath(baseURL, parsedUrl.Path)
baseUrlPath, err := url.JoinPath(baseURL, parsedUrl.Path)
if err != nil {
return nil, errors.Wrap(err, "could not join torrent url")
}
matched.TorrentURL = torrentURL
// reconstruct url
torrentUrl, _ := url.Parse(baseUrlPath)
torrentUrl.RawQuery = parsedUrl.RawQuery
matched.TorrentURL = torrentUrl.String()
}
if p.Match.TorrentName != "" {

View file

@ -200,6 +200,49 @@ func TestIndexerIRCParse_ParseMatch(t *testing.T) {
},
wantErr: false,
},
{
name: "test_04",
fields: fields{
Type: "",
ForceSizeUnit: "",
Lines: []IndexerIRCParseLine{
{
Test: nil,
Pattern: "New Torrent in category \\[([^\\]]*)\\] (.*) \\(([^\\)]*)\\) uploaded! Download\\: (https?\\:\\/\\/[^\\/]+\\/).+id=(.+)",
Vars: []string{
"category",
"torrentName",
"uploader",
"freeleech",
"baseUrl",
"torrentId",
},
},
},
Match: IndexerIRCParseMatch{
TorrentURL: "/rss/?action=download&key={{ .key }}&token={{ .token }}&hash={{ .torrentId }}&title={{ .torrentName }}",
Encode: []string{"torrentName"},
},
},
args: args{
baseURL: "https://mock.local/",
vars: map[string]string{
"category": "Movies/Remux",
"torrentName": "The Show 2019 S03E08 2160p DV WEBRip 6CH x265 HEVC-GROUP",
"uploader": "Anonymous",
"torrentSize": "",
"baseUrl": "https://mock.local/",
"torrentId": "240860011",
"key": "KEY",
"token": "TOKEN",
"rsskey": "00000000000000000000",
},
},
want: &IndexerIRCParseMatched{
TorrentURL: "https://mock.local/rss/?action=download&key=KEY&token=TOKEN&hash=240860011&title=The+Show+2019+S03E08+2160p+DV+WEBRip+6CH+x265+HEVC-GROUP",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {