mirror of https://github.com/velour/catbase.git
files: update deletion script
This commit is contained in:
parent
40d057b6a6
commit
e290760e44
|
@ -34,21 +34,34 @@ func main() {
|
||||||
ticker := time.NewTicker(time.Second * time.Duration(*rateLimit))
|
ticker := time.NewTicker(time.Second * time.Duration(*rateLimit))
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
page := 1
|
||||||
|
totalFiles := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
files, count := getFiles()
|
files, count := getFiles(page)
|
||||||
log.Debug().Msgf("Got %d files, count is %d", len(files), count)
|
totalFiles += len(files)
|
||||||
|
log.Debug().Msgf("Page %d: got %d files, count is %d",
|
||||||
|
page, len(files), count)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
downloadFile(f)
|
downloadFile(f)
|
||||||
deleteFile(f)
|
deleteFile(f)
|
||||||
}
|
}
|
||||||
if count == 1 {
|
if count < 1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
<-ticker.C
|
<-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{}
|
files := fileResp{}
|
||||||
|
|
||||||
var toTime time.Time
|
var toTime time.Time
|
||||||
|
@ -69,12 +82,15 @@ func getFiles() ([]slackFile, int) {
|
||||||
"count", strconv.Itoa(*limit),
|
"count", strconv.Itoa(*limit),
|
||||||
"types", *types,
|
"types", *types,
|
||||||
"ts_to", strconv.FormatInt(toTime.Unix(), 10),
|
"ts_to", strconv.FormatInt(toTime.Unix(), 10),
|
||||||
|
"ts_from", "0",
|
||||||
|
"page", strconv.Itoa(page),
|
||||||
)
|
)
|
||||||
|
|
||||||
err = json.Unmarshal(body, &files)
|
err = json.Unmarshal(body, &files)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
log.Info().
|
log.Info().
|
||||||
|
Int("page", page).
|
||||||
Int("count", files.Paging.Count).
|
Int("count", files.Paging.Count).
|
||||||
Int("total", files.Paging.Total).
|
Int("total", files.Paging.Total).
|
||||||
Bool("ok", files.Ok).
|
Bool("ok", files.Ok).
|
||||||
|
|
Loading…
Reference in New Issue