-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_download.go
46 lines (37 loc) · 922 Bytes
/
do_download.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"log"
"os"
securejoin "github.com/cyphar/filepath-securejoin"
)
// TODO be careful to not expose sitemapgenerator files when vendored...
func doDownload(urlBase64, token, outDir string) {
if outDir == "" {
log.Fatalln("no out dir provided")
}
currentPath, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
outPath, err := securejoin.SecureJoin(currentPath, outDir)
if err != nil {
log.Fatalln(err)
}
err = downloadFile(urlBase64, outPath+"/sitemap.xml", token)
if err != nil {
log.Fatalln(err)
}
stats, err := getStats(urlBase64, token)
if err != nil {
log.Fatalln(err)
}
for i := 0; i < stats.SitemapIndexCount; i++ {
format := "sitemap.%0" + fmt.Sprintf("%d", stats.SitemapIndexNumberOfDigits) + "d.xml"
filename := fmt.Sprintf(format, i)
err = downloadFile(urlBase64, outPath+"/"+filename, token)
if err != nil {
log.Fatalln(err)
}
}
}