add numbering

This commit is contained in:
joren
2026-03-11 19:56:37 +01:00
parent 8591ae283e
commit b8e6180b35
2 changed files with 17 additions and 9 deletions

View File

@@ -22,15 +22,17 @@ type Client struct {
CourseID string
CourseName string
FilesOnly bool
ModuleNumbers bool
downloadedFiles map[string]bool
}
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly bool) *Client {
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly, moduleNumbers bool) *Client {
return &Client{
HTTPClient: httpClient,
AccessToken: accessToken,
CourseID: courseID,
FilesOnly: filesOnly,
ModuleNumbers: moduleNumbers,
downloadedFiles: make(map[string]bool),
}
}
@@ -152,15 +154,20 @@ func (c *Client) DownloadModules(courseRoot string) {
json.NewDecoder(resp.Body).Decode(&modules)
resp.Body.Close()
for _, mod := range modules {
for i, mod := range modules {
modName := mod.Name
if c.ModuleNumbers {
modName = fmt.Sprintf("[%d] %s", i+1, mod.Name)
}
modBaseDir := courseRoot
if !c.FilesOnly {
modBaseDir = filepath.Join(courseRoot, "Modules", utils.Sanitize(mod.Name))
modBaseDir = filepath.Join(courseRoot, "Modules", utils.Sanitize(modName))
}
os.MkdirAll(modBaseDir, 0o755)
if !c.FilesOnly {
fmt.Printf("\n[Module] %s\n", mod.Name)
fmt.Printf("\n[Module] %s\n", modName)
}
subHeaderStack := []string{}