Skip to content

Commit

Permalink
bit of a clean
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleSanderson authored Nov 24, 2024
1 parent 690ad0b commit 2efc946
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ func getClient(req *upgradereq) error {

c, ok := clientmap.Get(s)
if !ok {
c = qbittorrent.NewClient(qbittorrent.Config{
Host: req.Host,
Username: req.User,
Password: req.Password,
})
c = qbittorrent.NewClient(s)

if err := c.Login(); err != nil {
return err
Expand Down Expand Up @@ -1229,7 +1225,7 @@ func handleAutobrrFilterUpdate(w http.ResponseWriter, r *http.Request) {
return
}

singlemap := make(map[string]struct{})
singlemap := make(map[string]struct{}, len(mp.e))
sane := regexp.MustCompile(`(\?+\?)`)
replace := regexp.MustCompile("([\x00-\\/\\:-@\\[-\\`\\{-\\~])")

Expand All @@ -1245,10 +1241,6 @@ func handleAutobrrFilterUpdate(w http.ResponseWriter, r *http.Request) {
}
}

submit := struct {
Shows string
}{}

buf := make([]string, 0, len(singlemap))
for k := range singlemap {
if len(k) < 1 {
Expand All @@ -1260,19 +1252,22 @@ func handleAutobrrFilterUpdate(w http.ResponseWriter, r *http.Request) {
singlemap = nil

sort.Strings(buf)
for _, k := range buf {
submit.Shows += k + ","
submit := struct {
Shows string
}{
Shows: strings.Trim(strings.Join(buf, ","), " ,"),
}

submit.Shows = strings.Trim(submit.Shows, " ,")

body, err := json.Marshal(submit)
if err != nil {
http.Error(w, fmt.Sprintf("Unable to marshall qbittorrent data: %q\n", err), 465)
return
body := &bytes.Buffer{}
{
enc := json.NewEncoder(body)
if err := enc.Encode(submit); err != nil {
http.Error(w, fmt.Sprintf("Unable to marshall qbittorrent data: %q\n", err), 465)
return
}
}

newreq, err := http.NewRequestWithContext(context.Background(), http.MethodPatch, req.AutobrrHost+"/api/filters/"+fmt.Sprintf("%d", req.FilterID), bytes.NewBuffer(body))
newreq, err := http.NewRequestWithContext(context.Background(), http.MethodPatch, req.AutobrrHost+"/api/filters/"+fmt.Sprintf("%d", req.FilterID), body)
if err != nil {
http.Error(w, fmt.Sprintf("Unable to create new http request: %q\n", err), 463)
return
Expand Down

0 comments on commit 2efc946

Please sign in to comment.