dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 0dee26094d8e3f8262ed2b9ed7f36f6efdadec02
parent e991ca461d47007f8c179859a921c1874a7a6e94
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri,  3 Feb 2023 16:21:01 -0800

skip already downloaded files

Diffstat:
Mcmd/dkfdownload/main.go | 33+++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/cmd/dkfdownload/main.go b/cmd/dkfdownload/main.go @@ -63,20 +63,23 @@ func main() { client := doGetClient(isLocal, httpTimeout) // Download metadata file - body := url.Values{} - body.Set("init", "1") - req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID+"/dkfdownload", strings.NewReader(body.Encode())) - req.Header.Set("User-Agent", userAgent) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - resp, err := client.Do(req) + by, err := os.ReadFile(filepath.Join(filedropUUID, "metadata")) if err != nil { - logrus.Fatalln(err) - } - defer resp.Body.Close() - by, _ := io.ReadAll(resp.Body) + body := url.Values{} + body.Set("init", "1") + req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID+"/dkfdownload", strings.NewReader(body.Encode())) + req.Header.Set("User-Agent", userAgent) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + resp, err := client.Do(req) + if err != nil { + logrus.Fatalln(err) + } + defer resp.Body.Close() + by, _ = io.ReadAll(resp.Body) - _ = os.Mkdir(filedropUUID, 0755) - _ = os.WriteFile(filepath.Join(filedropUUID, "metadata"), by, 0644) + _ = os.Mkdir(filedropUUID, 0755) + _ = os.WriteFile(filepath.Join(filedropUUID, "metadata"), by, 0644) + } // Read metadata information lines := strings.Split(string(by), "\n") @@ -195,6 +198,12 @@ func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID string, chunksCh chan start := time.Now() logrus.Infof("Thread #%03d | chunk #%03d", i, chunkNum) hasToSucceed(func() error { + partFileName := fmt.Sprintf("part_%d", chunkNum) + if _, err := os.Stat(filepath.Join(filedropUUID, partFileName)); err == nil { + logrus.Infof("Thread #%03d | chunk #%03d; skip", i, chunkNum) + return nil + } + start = time.Now() body := url.Values{} body.Set("chunk", strconv.FormatInt(chunkNum, 10))