]> BookStack Code Mirror - api-scripts/blob - go-export-page-content/content-map-funcs.go
Added bsfs to community project list
[api-scripts] / go-export-page-content / content-map-funcs.go
1 package main
2
3 import (
4         "time"
5 )
6
7 func getBookMap(api *BookStackApi) map[int]Book {
8         var books []Book
9         var byId = make(map[int]Book)
10
11         page := 1
12         hasMoreBooks := true
13         for hasMoreBooks {
14                 time.Sleep(time.Second / 2)
15                 newBooks, _ := api.GetBooks(200, page)
16                 hasMoreBooks = len(newBooks) == 200
17                 page++
18                 books = append(books, newBooks...)
19         }
20
21         for _, book := range books {
22                 byId[book.Id] = book
23         }
24
25         return byId
26 }
27
28 func getChapterMap(api *BookStackApi) map[int]Chapter {
29         var chapters []Chapter
30         var byId = make(map[int]Chapter)
31
32         page := 1
33         hasMoreChapters := true
34         for hasMoreChapters {
35                 time.Sleep(time.Second / 2)
36                 newChapters, _ := api.GetChapters(200, page)
37                 hasMoreChapters = len(newChapters) == 200
38                 page++
39                 chapters = append(chapters, newChapters...)
40         }
41
42         for _, chapter := range chapters {
43                 byId[chapter.Id] = chapter
44         }
45
46         return byId
47 }
48
49 func getPageMap(api *BookStackApi) map[int]Page {
50         var pages []Page
51         var byId = make(map[int]Page)
52
53         page := 1
54         hasMorePages := true
55         for hasMorePages {
56                 time.Sleep(time.Second / 2)
57                 newPages, _ := api.GetPages(200, page)
58                 hasMorePages = len(newPages) == 200
59                 page++
60                 pages = append(pages, newPages...)
61         }
62
63         for _, page := range pages {
64                 byId[page.Id] = page
65         }
66
67         return byId
68 }