mirror of
https://github.com/sstent/garminsync-go.git
synced 2026-02-02 12:32:18 +00:00
solving sync flow
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify, send_file
|
||||||
|
import io
|
||||||
from garminconnect import Garmin
|
from garminconnect import Garmin
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -77,6 +78,26 @@ def get_activity_details(activity_id):
|
|||||||
logger.error(f"Error fetching activity details: {str(e)}")
|
logger.error(f"Error fetching activity details: {str(e)}")
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/activities/<activity_id>/download', methods=['GET'])
|
||||||
|
def download_activity(activity_id):
|
||||||
|
"""Endpoint to download activity data."""
|
||||||
|
api = init_api()
|
||||||
|
if not api:
|
||||||
|
return jsonify({"error": "Failed to connect to Garmin API"}), 500
|
||||||
|
|
||||||
|
try:
|
||||||
|
format = request.args.get('format', 'fit') # Default to FIT format
|
||||||
|
file_data = api.download_activity(activity_id, format=format)
|
||||||
|
return send_file(
|
||||||
|
io.BytesIO(file_data),
|
||||||
|
mimetype='application/octet-stream',
|
||||||
|
as_attachment=True,
|
||||||
|
download_name=f'activity_{activity_id}.{format}'
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error downloading activity: {str(e)}")
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
@app.route('/health', methods=['GET'])
|
@app.route('/health', methods=['GET'])
|
||||||
def health_check():
|
def health_check():
|
||||||
"""Health check endpoint."""
|
"""Health check endpoint."""
|
||||||
|
|||||||
@@ -105,9 +105,26 @@ func (c *Client) GetActivities(start, limit int) ([]GarminActivity, error) {
|
|||||||
|
|
||||||
// Helper function removed - no longer needed
|
// Helper function removed - no longer needed
|
||||||
|
|
||||||
// DownloadActivity downloads an activity from Garmin Connect (stub implementation)
|
// DownloadActivity downloads an activity via the Python API wrapper
|
||||||
func (c *Client) DownloadActivity(activityID int, format string) ([]byte, error) {
|
func (c *Client) DownloadActivity(activityID int, format string) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("DownloadActivity not implemented - use Python API")
|
url := fmt.Sprintf("%s/activities/%d/download?format=%s", c.baseURL, activityID, format)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := c.httpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("API returned status %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return io.ReadAll(resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetActivityDetails retrieves details for a specific activity from the Python API wrapper
|
// GetActivityDetails retrieves details for a specific activity from the Python API wrapper
|
||||||
|
|||||||
Reference in New Issue
Block a user