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
|
||||
downloadFormat string
|
||||
outputDir string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -72,6 +73,7 @@ func init() {
|
||||
|
||||
activitiesCmd.AddCommand(downloadActivitiesCmd)
|
||||
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)
|
||||
searchActivitiesCmd.Flags().StringP("query", "q", "", "Query string to search for activities")
|
||||
@@ -180,10 +182,10 @@ func runDownloadActivity(cmd *cobra.Command, args []string) error {
|
||||
|
||||
opts := garmin.DownloadOptions{
|
||||
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 {
|
||||
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:**
|
||||
- [ ] Research Garmin's download endpoints
|
||||
- [ ] Implement format detection and conversion
|
||||
- [ ] Add file writing with proper naming
|
||||
- [x] Research Garmin's download endpoints
|
||||
- [x] Implement format detection and conversion
|
||||
- [x] Add file writing with proper naming
|
||||
- [ ] Implement progress indication
|
||||
- [ ] Add download validation
|
||||
- [ ] Error handling for failed downloads
|
||||
- [x] Error handling for failed downloads
|
||||
|
||||
**Deliverables:**
|
||||
- [ ] Working download for at least GPX format
|
||||
- [x] Working download for at least GPX format
|
||||
- [ ] Progress indication during download
|
||||
- [ ] Proper error handling
|
||||
- [x] Proper error handling
|
||||
|
||||
#### 1C.2: Multi-Format Support
|
||||
**Duration: 2 days**
|
||||
|
||||
@@ -76,8 +76,31 @@ func (c *Client) GetActivity(activityID int) (*activities.ActivityDetail, error)
|
||||
|
||||
// DownloadActivity downloads activity data
|
||||
func (c *Client) DownloadActivity(activityID int, opts activities.DownloadOptions) error {
|
||||
// TODO: Implement internalClient.Client.DownloadActivity
|
||||
return fmt.Errorf("not implemented")
|
||||
// TODO: Determine file extension based on format
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user