Compare commits
2 Commits
05ed4dd4ed
...
v1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| be63064bee | |||
| cd259e01a3 |
@@ -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
|
||||||
|
|||||||
@@ -17,21 +17,19 @@ 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),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user