Skip to content

Commit

Permalink
Remove explicit cookie setting and url-decode filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
gnojus committed Jul 23, 2021
1 parent f45b293 commit a16b79e
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions transfer/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"regexp"
)

Expand Down Expand Up @@ -62,7 +63,8 @@ func FilenameFromUrl(URL string) string {
reg := regexp.MustCompile(`/([^/]+)\?`)
tmp := reg.FindStringSubmatch(URL)
if tmp != nil {
return tmp[1]
s, _ := url.QueryUnescape(tmp[1])
return s
}
return ""
}
Expand All @@ -71,7 +73,6 @@ func getDownloadLink(client *http.Client, data transferData) (URL string, err er
url := fmt.Sprintf("%s/transfers/%s/download", baseApi, data.transferId)
req, err := createRequest("POST", url, headers{
"X-CSRF-Token": data.csrfToken,
"cookie": "_wt_session=" + data.wtSession,
"content-type": "application/json",
"X-Requested-With": "XMLHttpRequest",
}, data.reqData)
Expand Down Expand Up @@ -125,18 +126,6 @@ func getTransferData(resp *http.Response) (out transferData, err error) {
}
out.reqData.Intent = "entire_transfer"

if out.wtSession, ok = getCookieValue("_wt_session", resp); !ok {
return out, errors.New("Unable to get _wt_session cookie")
}
return
}

func getCookieValue(name string, resp *http.Response) (out string, exists bool) {
for _, cookie := range resp.Cookies() {
if cookie.Name == name {
return cookie.Value, true
}
}
return
}

Expand Down

0 comments on commit a16b79e

Please sign in to comment.