From 956bccd69f7e3d645c8e61c97ea16c2a1106bfb5 Mon Sep 17 00:00:00 2001 From: ze0s <43699394+zze0s@users.noreply.github.com> Date: Sun, 23 Apr 2023 20:54:39 +0200 Subject: [PATCH] feat(releases): set freeleech percent 100 with freeleech bool (#872) * feat(releases): set freeleech to freeleech percent 100 * fix(releases): check if freeleechpercent is gt 0 --- internal/domain/release.go | 33 +++++++++++++------------ internal/domain/release_test.go | 43 ++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/internal/domain/release.go b/internal/domain/release.go index 6e8a7ea..a20666b 100644 --- a/internal/domain/release.go +++ b/internal/domain/release.go @@ -546,6 +546,8 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro fl := StringEqualFoldMulti(freeleech, "freeleech", "yes", "1", "VIP") if fl { r.Freeleech = true + // default to 100 and override if freeleechPercent is present in next function + r.FreeleechPercent = 100 r.Bonus = append(r.Bonus, "Freeleech") } } @@ -560,22 +562,23 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro //log.Debug().Msgf("bad freeleechPercent var: %v", year) } - r.Freeleech = true - r.FreeleechPercent = freeleechPercentInt - - r.Bonus = append(r.Bonus, "Freeleech") - - switch freeleechPercentInt { - case 25: - r.Bonus = append(r.Bonus, "Freeleech25") - case 50: - r.Bonus = append(r.Bonus, "Freeleech50") - case 75: - r.Bonus = append(r.Bonus, "Freeleech75") - case 100: - r.Bonus = append(r.Bonus, "Freeleech100") + if (freeleechPercentInt > 0) { + r.Freeleech = true + r.FreeleechPercent = freeleechPercentInt + + r.Bonus = append(r.Bonus, "Freeleech") + + switch freeleechPercentInt { + case 25: + r.Bonus = append(r.Bonus, "Freeleech25") + case 50: + r.Bonus = append(r.Bonus, "Freeleech50") + case 75: + r.Bonus = append(r.Bonus, "Freeleech75") + case 100: + r.Bonus = append(r.Bonus, "Freeleech100") + } } - } if uploader, err := getStringMapValue(varMap, "uploader"); err == nil { diff --git a/internal/domain/release_test.go b/internal/domain/release_test.go index f76126d..04c4332 100644 --- a/internal/domain/release_test.go +++ b/internal/domain/release_test.go @@ -297,12 +297,13 @@ func TestRelease_MapVars(t *testing.T) { name: "2", fields: &Release{}, want: &Release{ - TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2", - Category: "tv", - Freeleech: true, - Bonus: []string{"Freeleech"}, - Uploader: "Anon", - Size: uint64(10000000000), + TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2", + Category: "tv", + Freeleech: true, + FreeleechPercent: 100, + Bonus: []string{"Freeleech"}, + Uploader: "Anon", + Size: uint64(10000000000), }, args: args{ varMap: map[string]string{ @@ -475,13 +476,14 @@ func TestRelease_MapVars(t *testing.T) { name: "10", fields: &Release{}, want: &Release{ - TorrentName: "Greatest Anime Ever", - Year: 2022, - Group: "GROUP1", - Tags: []string{"comedy", "fantasy", "school.life", "shounen", "slice.of.life"}, - Uploader: "Tester", - Freeleech: true, - Bonus: []string{"Freeleech"}, + TorrentName: "Greatest Anime Ever", + Year: 2022, + Group: "GROUP1", + Tags: []string{"comedy", "fantasy", "school.life", "shounen", "slice.of.life"}, + Uploader: "Tester", + Freeleech: true, + FreeleechPercent: 100, + Bonus: []string{"Freeleech"}, }, args: args{varMap: map[string]string{ "torrentName": "Greatest Anime Ever", @@ -496,13 +498,14 @@ func TestRelease_MapVars(t *testing.T) { name: "11", fields: &Release{}, want: &Release{ - TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2", - Category: "tv", - Freeleech: true, - Bonus: []string{"Freeleech"}, - Uploader: "Anon", - Size: uint64(10000000000), - Tags: []string{"comedy", "science fiction", "fantasy", "school.life", "shounen", "slice.of.life"}, + TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2", + Category: "tv", + Freeleech: true, + FreeleechPercent: 100, + Bonus: []string{"Freeleech"}, + Uploader: "Anon", + Size: uint64(10000000000), + Tags: []string{"comedy", "science fiction", "fantasy", "school.life", "shounen", "slice.of.life"}, }, args: args{ varMap: map[string]string{