Merge pull request 'Prevent dupes in fo mode' (#3) from files-only into main

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2026-03-11 17:52:41 +01:00

View File

@@ -17,19 +17,21 @@ import (
)
type Client struct {
HTTPClient *http.Client
AccessToken string
CourseID string
CourseName string
FilesOnly bool
HTTPClient *http.Client
AccessToken string
CourseID string
CourseName string
FilesOnly bool
downloadedFiles map[string]bool
}
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly bool) *Client {
return &Client{
HTTPClient: httpClient,
AccessToken: accessToken,
CourseID: courseID,
FilesOnly: filesOnly,
HTTPClient: httpClient,
AccessToken: accessToken,
CourseID: courseID,
FilesOnly: filesOnly,
downloadedFiles: make(map[string]bool),
}
}
@@ -82,6 +84,13 @@ func (c *Client) DownloadCourseFiles(root string) {
fileCount := 0
for _, file := range files {
if c.FilesOnly {
if c.downloadedFiles[file.DisplayName] {
continue
}
c.downloadedFiles[file.DisplayName] = true
}
rawFolderPath := folderMap[file.FolderID]
safeFolderPath := utils.SanitizePath(rawFolderPath)
@@ -223,11 +232,18 @@ func (c *Client) downloadModuleFile(item models.ModuleItem, dir string) {
return
}
if c.FilesOnly {
if c.downloadedFiles[fileMeta.DisplayName] {
return
}
c.downloadedFiles[fileMeta.DisplayName] = true
}
ext := filepath.Ext(fileMeta.DisplayName)
origBase := strings.TrimSuffix(fileMeta.DisplayName, ext)
fileName := fileMeta.DisplayName
if !strings.EqualFold(origBase, item.Title) && item.Title != "" {
if !c.FilesOnly && !strings.EqualFold(origBase, item.Title) && item.Title != "" {
fileName = fmt.Sprintf("%s (%s)%s", origBase, item.Title, ext)
}