From e290760e4431892618162a30e457149a1000d9f6 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 10 Apr 2021 09:25:49 -0400 Subject: [PATCH] files: update deletion script --- util/files/main.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/util/files/main.go b/util/files/main.go index e12ed97..e18e2f2 100644 --- a/util/files/main.go +++ b/util/files/main.go @@ -34,21 +34,34 @@ func main() { ticker := time.NewTicker(time.Second * time.Duration(*rateLimit)) defer ticker.Stop() + page := 1 + totalFiles := 0 + for { - files, count := getFiles() - log.Debug().Msgf("Got %d files, count is %d", len(files), count) + files, count := getFiles(page) + totalFiles += len(files) + log.Debug().Msgf("Page %d: got %d files, count is %d", + page, len(files), count) for _, f := range files { downloadFile(f) deleteFile(f) } - if count == 1 { + if count < 1 { break } <-ticker.C + if page >= count { + if totalFiles == 0 { + break + } + totalFiles = 0 + page = 0 + } + page++ } } -func getFiles() ([]slackFile, int) { +func getFiles(page int) ([]slackFile, int) { files := fileResp{} var toTime time.Time @@ -69,12 +82,15 @@ func getFiles() ([]slackFile, int) { "count", strconv.Itoa(*limit), "types", *types, "ts_to", strconv.FormatInt(toTime.Unix(), 10), + "ts_from", "0", + "page", strconv.Itoa(page), ) err = json.Unmarshal(body, &files) checkErr(err) log.Info(). + Int("page", page). Int("count", files.Paging.Count). Int("total", files.Paging.Total). Bool("ok", files.Ok).