commit 177fd402bd26e79011431c5b4e09899d1f25ec56
parent 9b1dd9a8a17d7340459bcb9e8e1e6e45a1838896
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 3 Feb 2023 21:09:16 -0800
cleanup
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/cmd/dkfdownload/main.go b/cmd/dkfdownload/main.go
@@ -63,6 +63,7 @@ func main() {
flag.Parse()
baseUrl := Ternary(isLocal, localhostAddr, dkfBaseURL)
+ endpoint := baseUrl + "/api/v1/file-drop/" + filedropUUID + "/dkfdownload"
client := doGetClient(isLocal, httpTimeout)
@@ -71,7 +72,7 @@ func main() {
if err != nil {
body := url.Values{}
body.Set("init", "1")
- req, _ := http.NewRequest(http.MethodPost, baseUrl+"/api/v1/file-drop/"+filedropUUID+"/dkfdownload", strings.NewReader(body.Encode()))
+ req, _ := http.NewRequest(http.MethodPost, endpoint, strings.NewReader(body.Encode()))
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("DKF_API_KEY", apiKey)
@@ -127,7 +128,7 @@ func main() {
wg := &sync.WaitGroup{}
wg.Add(nbThreads)
for i := 0; i < nbThreads; i++ {
- go work(i, wg, baseUrl, filedropUUID, apiKey, chunksCh, isLocal, httpTimeout, nbChunks)
+ go work(i, wg, endpoint, filedropUUID, apiKey, chunksCh, isLocal, httpTimeout, nbChunks)
time.Sleep(25 * time.Millisecond)
}
wg.Wait()
@@ -199,7 +200,7 @@ func main() {
logrus.Infof("all done in %s", ShortDur(time.Since(start)))
}
-func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID, apiKey string, chunksCh chan int64, isLocal bool, httpTimeout time.Duration, nbChunks int64) {
+func work(i int, wg *sync.WaitGroup, endpoint, filedropUUID, apiKey string, chunksCh chan int64, isLocal bool, httpTimeout time.Duration, nbChunks int64) {
defer wg.Done()
client := doGetClient(isLocal, httpTimeout)
for chunkNum := range chunksCh {
@@ -209,7 +210,7 @@ func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID, apiKey string, chunk
start = time.Now()
body := url.Values{}
body.Set("chunk", strconv.FormatInt(chunkNum, 10))
- req, err := http.NewRequest(http.MethodPost, baseUrl+"/api/v1/file-drop/"+filedropUUID+"/dkfdownload", strings.NewReader(body.Encode()))
+ req, err := http.NewRequest(http.MethodPost, endpoint, strings.NewReader(body.Encode()))
if err != nil {
return err
}