2 Commits

Author SHA1 Message Date
be63064bee Update README.md 2026-03-11 17:40:48 +01:00
cd259e01a3 Merge pull request 'Add files only mode' (#2) from files-only into main
Reviewed-on: #2
2026-03-11 17:38:56 +01:00
2 changed files with 16 additions and 26 deletions

View File

@@ -21,6 +21,12 @@ go build -o canvasarchiver ./cmd/canvasarchiver
./canvasarchiver
```
Or
```bash
./canvasarchiver -fo
```
For files-only mode.
2. On first run, you'll be prompted to authenticate:
- Visit the provided OAuth URL
- Authorize the application

View File

@@ -17,21 +17,19 @@ import (
)
type Client struct {
HTTPClient *http.Client
AccessToken string
CourseID string
CourseName string
FilesOnly bool
downloadedFiles map[string]bool
HTTPClient *http.Client
AccessToken string
CourseID string
CourseName string
FilesOnly bool
}
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly bool) *Client {
return &Client{
HTTPClient: httpClient,
AccessToken: accessToken,
CourseID: courseID,
FilesOnly: filesOnly,
downloadedFiles: make(map[string]bool),
HTTPClient: httpClient,
AccessToken: accessToken,
CourseID: courseID,
FilesOnly: filesOnly,
}
}
@@ -84,13 +82,6 @@ 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)
@@ -232,18 +223,11 @@ 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 !c.FilesOnly && !strings.EqualFold(origBase, item.Title) && item.Title != "" {
if !strings.EqualFold(origBase, item.Title) && item.Title != "" {
fileName = fmt.Sprintf("%s (%s)%s", origBase, item.Title, ext)
}