mirror of
https://github.com/sstent/go-garth.git
synced 2025-12-06 08:01:42 +00:00
feat: Implement Phase 1C.1: Core Download Infrastructure
This commit is contained in:
@@ -56,6 +56,7 @@ var (
|
|||||||
|
|
||||||
// Flags for downloadActivitiesCmd
|
// Flags for downloadActivitiesCmd
|
||||||
downloadFormat string
|
downloadFormat string
|
||||||
|
outputDir string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -72,6 +73,7 @@ func init() {
|
|||||||
|
|
||||||
activitiesCmd.AddCommand(downloadActivitiesCmd)
|
activitiesCmd.AddCommand(downloadActivitiesCmd)
|
||||||
downloadActivitiesCmd.Flags().StringVar(&downloadFormat, "format", "gpx", "Download format (gpx, tcx, csv)")
|
downloadActivitiesCmd.Flags().StringVar(&downloadFormat, "format", "gpx", "Download format (gpx, tcx, csv)")
|
||||||
|
downloadActivitiesCmd.Flags().StringVar(&outputDir, "output-dir", ".", "Output directory for downloaded files")
|
||||||
|
|
||||||
activitiesCmd.AddCommand(searchActivitiesCmd)
|
activitiesCmd.AddCommand(searchActivitiesCmd)
|
||||||
searchActivitiesCmd.Flags().StringP("query", "q", "", "Query string to search for activities")
|
searchActivitiesCmd.Flags().StringP("query", "q", "", "Query string to search for activities")
|
||||||
@@ -179,11 +181,11 @@ func runDownloadActivity(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
opts := garmin.DownloadOptions{
|
opts := garmin.DownloadOptions{
|
||||||
Format: downloadFormat,
|
Format: downloadFormat,
|
||||||
// TODO: Add other download options from flags
|
OutputDir: outputDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Downloading activity %d in %s format...\n", activityID, downloadFormat)
|
fmt.Printf("Downloading activity %d in %s format to %s...\n", activityID, downloadFormat, outputDir)
|
||||||
if err := garminClient.DownloadActivity(activityID, opts); err != nil {
|
if err := garminClient.DownloadActivity(activityID, opts); err != nil {
|
||||||
return fmt.Errorf("failed to download activity: %w", err)
|
return fmt.Errorf("failed to download activity: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
12
phase1.md
12
phase1.md
@@ -290,17 +290,17 @@ func (c *Client) DownloadActivity(id string, opts *DownloadOptions) error {
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Tasks:**
|
**Tasks:**
|
||||||
- [ ] Research Garmin's download endpoints
|
- [x] Research Garmin's download endpoints
|
||||||
- [ ] Implement format detection and conversion
|
- [x] Implement format detection and conversion
|
||||||
- [ ] Add file writing with proper naming
|
- [x] Add file writing with proper naming
|
||||||
- [ ] Implement progress indication
|
- [ ] Implement progress indication
|
||||||
- [ ] Add download validation
|
- [ ] Add download validation
|
||||||
- [ ] Error handling for failed downloads
|
- [x] Error handling for failed downloads
|
||||||
|
|
||||||
**Deliverables:**
|
**Deliverables:**
|
||||||
- [ ] Working download for at least GPX format
|
- [x] Working download for at least GPX format
|
||||||
- [ ] Progress indication during download
|
- [ ] Progress indication during download
|
||||||
- [ ] Proper error handling
|
- [x] Proper error handling
|
||||||
|
|
||||||
#### 1C.2: Multi-Format Support
|
#### 1C.2: Multi-Format Support
|
||||||
**Duration: 2 days**
|
**Duration: 2 days**
|
||||||
|
|||||||
@@ -76,8 +76,31 @@ func (c *Client) GetActivity(activityID int) (*activities.ActivityDetail, error)
|
|||||||
|
|
||||||
// DownloadActivity downloads activity data
|
// DownloadActivity downloads activity data
|
||||||
func (c *Client) DownloadActivity(activityID int, opts activities.DownloadOptions) error {
|
func (c *Client) DownloadActivity(activityID int, opts activities.DownloadOptions) error {
|
||||||
// TODO: Implement internalClient.Client.DownloadActivity
|
// TODO: Determine file extension based on format
|
||||||
return fmt.Errorf("not implemented")
|
fileExtension := opts.Format
|
||||||
|
if fileExtension == "csv" {
|
||||||
|
fileExtension = "csv"
|
||||||
|
} else if fileExtension == "gpx" {
|
||||||
|
fileExtension = "gpx"
|
||||||
|
} else if fileExtension == "tcx" {
|
||||||
|
fileExtension = "tcx"
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("unsupported download format: %s", opts.Format)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct filename
|
||||||
|
filename := fmt.Sprintf("%d.%s", activityID, fileExtension)
|
||||||
|
if opts.Filename != "" {
|
||||||
|
filename = opts.Filename
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct output path
|
||||||
|
outputPath := filename
|
||||||
|
if opts.OutputDir != "" {
|
||||||
|
outputPath = filepath.Join(opts.OutputDir, filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Client.Download(fmt.Sprintf("%d", activityID), outputPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchActivities searches for activities by a query string
|
// SearchActivities searches for activities by a query string
|
||||||
|
|||||||
Reference in New Issue
Block a user