Prevent dupes in fo mode #3

Merged
Joren merged 2 commits from files-only into main 2026-03-11 17:52:41 +01:00

View File

@@ -22,6 +22,7 @@ type Client struct {
CourseID string
CourseName string
FilesOnly bool
downloadedFiles map[string]bool
}
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly bool) *Client {
@@ -30,6 +31,7 @@ func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly
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)
}