]> BookStack Code Mirror - api-scripts/commitdiff
Fixed go script path, added a little concurrency
authorDan Brown <redacted>
Sun, 10 Apr 2022 16:00:25 +0000 (17:00 +0100)
committerDan Brown <redacted>
Sun, 10 Apr 2022 16:00:25 +0000 (17:00 +0100)
go-export-page-content/export.go
go-export-page-content/readme.md

index 8825bf6369f039e0e76a58dc25d5271c53d0a899..72d9d1f5991ba7549935f5784a0063eeefa2fca8 100644 (file)
@@ -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)
+       }
+}
index 9fea82c2c6b1f2c5cc1e136f0d8f09f02e2aad69..a38c10d33d7172240a891f9da32036a192d3cb25 100644 (file)
@@ -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.