From: Dan Brown Date: Sun, 10 Apr 2022 16:00:25 +0000 (+0100) Subject: Fixed go script path, added a little concurrency X-Git-Url: http://source.bookstackapp.com/api-scripts/commitdiff_plain/2d878429373646e3e2ad44dad2206c9162693db3 Fixed go script path, added a little concurrency --- diff --git a/go-export-page-content/export.go b/go-export-page-content/export.go index 8825bf6..72d9d1f 100644 --- a/go-export-page-content/export.go +++ b/go-export-page-content/export.go @@ -48,7 +48,7 @@ func main() { book := bookIdMap[fullPage.BookId] path := book.Slug if chapter, ok := chapterIdMap[fullPage.ChapterId]; ok { - path = "/" + chapter.Slug + path += "/" + chapter.Slug } // Get the html, or markdown, content from our page along with the file name @@ -74,14 +74,18 @@ func main() { // Write the content to the filesystem fPath := filepath.Join(absPath, fName) - err = os.WriteFile(fPath, []byte(content), 0644) - if err != nil { - panic(err) - } + go writeOutPageContent(fPath, content) // Wait to avoid hitting rate limits - time.Sleep(time.Second / 4) + time.Sleep(time.Second / 6) currentCount++ } } + +func writeOutPageContent(path string, content string) { + err := os.WriteFile(path, []byte(content), 0644) + if err != nil { + panic(err) + } +} diff --git a/go-export-page-content/readme.md b/go-export-page-content/readme.md index 9fea82c..a38c10d 100644 --- a/go-export-page-content/readme.md +++ b/go-export-page-content/readme.md @@ -5,6 +5,8 @@ Content will be written into a directory structure that mirrors the page's locat Note: This is only provided as an example. The project lacks full error handling and also disables HTTPS verification for easier use with self-signed certificates. +This project uses timeouts, and lacks async requesting, to respect potential rate limits. + ## Requirements [Go](https://go.dev/) is required to build this project.