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 ./canvasarchiver
``` ```
Or
```bash
./canvasarchiver -fo
```
For files-only mode.
2. On first run, you'll be prompted to authenticate: 2. On first run, you'll be prompted to authenticate:
- Visit the provided OAuth URL - Visit the provided OAuth URL
- Authorize the application - Authorize the application

View File

@@ -22,7 +22,6 @@ type Client struct {
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 {
@@ -31,7 +30,6 @@ func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly
AccessToken: accessToken, AccessToken: accessToken,
CourseID: courseID, CourseID: courseID,
FilesOnly: filesOnly, FilesOnly: filesOnly,
downloadedFiles: make(map[string]bool),
} }
} }
@@ -84,13 +82,6 @@ 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)
@@ -232,18 +223,11 @@ 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 !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) fileName = fmt.Sprintf("%s (%s)%s", origBase, item.Title, ext)
} }