Prevent dupes in fo mode #3
@@ -17,19 +17,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
AccessToken string
|
AccessToken string
|
||||||
CourseID string
|
CourseID string
|
||||||
CourseName string
|
CourseName string
|
||||||
FilesOnly bool
|
FilesOnly 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 bool) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
HTTPClient: httpClient,
|
HTTPClient: httpClient,
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
CourseID: courseID,
|
CourseID: courseID,
|
||||||
FilesOnly: filesOnly,
|
FilesOnly: filesOnly,
|
||||||
|
downloadedFiles: make(map[string]bool),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +84,13 @@ func (c *Client) DownloadCourseFiles(root string) {
|
|||||||
fileCount := 0
|
fileCount := 0
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
|
||||||
|
if c.FilesOnly {
|
||||||
|
if c.downloadedFiles[file.DisplayName] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.downloadedFiles[file.DisplayName] = true
|
||||||
|
}
|
||||||
|
|
||||||
rawFolderPath := folderMap[file.FolderID]
|
rawFolderPath := folderMap[file.FolderID]
|
||||||
safeFolderPath := utils.SanitizePath(rawFolderPath)
|
safeFolderPath := utils.SanitizePath(rawFolderPath)
|
||||||
|
|
||||||
@@ -223,11 +232,18 @@ func (c *Client) downloadModuleFile(item models.ModuleItem, dir string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.FilesOnly {
|
||||||
|
if c.downloadedFiles[fileMeta.DisplayName] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.downloadedFiles[fileMeta.DisplayName] = true
|
||||||
|
}
|
||||||
|
|
||||||
ext := filepath.Ext(fileMeta.DisplayName)
|
ext := filepath.Ext(fileMeta.DisplayName)
|
||||||
origBase := strings.TrimSuffix(fileMeta.DisplayName, ext)
|
origBase := strings.TrimSuffix(fileMeta.DisplayName, ext)
|
||||||
|
|
||||||
fileName := fileMeta.DisplayName
|
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)
|
fileName = fmt.Sprintf("%s (%s)%s", origBase, item.Title, ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user