From 05ed4dd4ed49a0cd66cc9a2611144046ceac2303 Mon Sep 17 00:00:00 2001 From: Joren Date: Wed, 11 Mar 2026 17:51:34 +0100 Subject: [PATCH] Prevent dupes in fo mode --- internal/canvas/client.go | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/internal/canvas/client.go b/internal/canvas/client.go index c460422..9e9beb1 100644 --- a/internal/canvas/client.go +++ b/internal/canvas/client.go @@ -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) }