diff --git a/pkg/converters/parse.go b/pkg/converters/parse.go index d22c5b8a..8e21ba69 100644 --- a/pkg/converters/parse.go +++ b/pkg/converters/parse.go @@ -16,6 +16,23 @@ func Parse(filename string, content []byte) (*gpx.GPX, error) { return ParseGPX(content) } + basename := path.Base(filename) + + c, err := parseContent(basename, content) + if err != nil { + return nil, err + } + + if c.Name != "" || len(c.Tracks) > 0 { + return c, nil + } + + c.Name = basename + + return c, nil +} + +func parseContent(filename string, content []byte) (*gpx.GPX, error) { suffix := path.Ext(filename) switch suffix { diff --git a/pkg/database/gpx_sample_1_test.go b/pkg/database/gpx_sample_1_test.go index 6f52ee07..ae6287fc 100644 --- a/pkg/database/gpx_sample_1_test.go +++ b/pkg/database/gpx_sample_1_test.go @@ -14,7 +14,7 @@ const GpxSample1 = ` - Untitled + Some name 25.600000381469727 diff --git a/pkg/database/workouts_test.go b/pkg/database/workouts_test.go index 70b1f0df..d94e8e17 100644 --- a/pkg/database/workouts_test.go +++ b/pkg/database/workouts_test.go @@ -64,7 +64,7 @@ func TestWorkout_Parse(t *testing.T) { assert.InDelta(t, 3125, w.Data.TotalDistance, 1) assert.InDelta(t, 3.297, w.Data.AverageSpeed, 0.01) assert.InDelta(t, 3.297, w.Data.AverageSpeedNoPause, 0.01) - assert.Equal(t, "Untitled", w.Name) + assert.Equal(t, "Some name", w.Name) assert.Nil(t, w.Data.Address) }