adds non-highlight photos to komoot sync
This commit is contained in:
@@ -164,7 +164,7 @@ func (k *KomootApi) fetchTours(page int) ([]KomootTour, error) {
|
||||
}
|
||||
|
||||
func (k *KomootApi) fetchDetailedTour(tour KomootTour) (*DetailedKomootTour, error) {
|
||||
url := fmt.Sprintf("https://api.komoot.de/v007/tours/%d?_embedded=coordinates,way_types,surfaces,directions,participants,timeline&directions=v2&fields=timeline&format=coordinate_array&timeline_highlights_fields=tips,recommenders", tour.ID)
|
||||
url := fmt.Sprintf("https://api.komoot.de/v007/tours/%d?_embedded=coordinates,way_types,surfaces,directions,participants,timeline,cover_images&directions=v2&fields=timeline&format=coordinate_array&timeline_highlights_fields=tips,recommenders", tour.ID)
|
||||
body, err := sendRequest(url, k.buildHeader())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -234,10 +234,19 @@ func createTrailFromTour(app *pocketbase.PocketBase, detailedTour *DetailedKomoo
|
||||
categoryId = category.Id
|
||||
}
|
||||
|
||||
var photos []*filesystem.File
|
||||
if len(detailedTour.Embedded.CoverImages.Embedded.Items) > 0 {
|
||||
photos, err = fetchRoutePhotos(detailedTour)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
photo, err := fetchPhoto(detailedTour.MapImage.Src, "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
photos = append(photos, photo)
|
||||
}
|
||||
|
||||
diffculty := detailedTour.Difficulty.Grade
|
||||
if diffculty == "" {
|
||||
@@ -262,7 +271,9 @@ func createTrailFromTour(app *pocketbase.PocketBase, detailedTour *DetailedKomoo
|
||||
"author": user,
|
||||
})
|
||||
|
||||
for _, photo := range photos {
|
||||
form.AddFiles("photos", photo)
|
||||
}
|
||||
form.AddFiles("gpx", gpx)
|
||||
|
||||
if err := form.Submit(); err != nil {
|
||||
@@ -327,6 +338,23 @@ func createWaypointsFromTour(app *pocketbase.PocketBase, tour *DetailedKomootTou
|
||||
return wpIds, nil
|
||||
}
|
||||
|
||||
func fetchRoutePhotos(tour *DetailedKomootTour) ([]*filesystem.File, error) {
|
||||
|
||||
photos := make([]*filesystem.File, len(tour.Embedded.CoverImages.Embedded.Items))
|
||||
|
||||
for i, img := range tour.Embedded.CoverImages.Embedded.Items {
|
||||
photo, err := fetchPhoto(img.Src, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
photos[i] = photo
|
||||
|
||||
//TODO: komoot photos can have location data. Maybe we should create a waypoint for those photos?
|
||||
}
|
||||
|
||||
return photos, nil
|
||||
}
|
||||
|
||||
func fetchWaypointPhotos(wp Item) ([]*filesystem.File, error) {
|
||||
|
||||
photos := make([]*filesystem.File, len(wp.Embedded.Reference.Embedded.Images.Embedded.Items))
|
||||
|
||||
@@ -246,6 +246,17 @@ type Coordinates struct {
|
||||
type DetailedTourEmbedded struct {
|
||||
Coordinates Coordinates `json:"coordinates"`
|
||||
Timeline Timeline `json:"timeline"`
|
||||
CoverImages CoverImages `json:"cover_images"`
|
||||
}
|
||||
|
||||
type CoverImages struct {
|
||||
Embedded CoverImagesEmbedded `json:"_embedded"`
|
||||
Links Links `json:"_links"`
|
||||
Page Page `json:"page"`
|
||||
}
|
||||
|
||||
type CoverImagesEmbedded struct {
|
||||
Items []ImageItem `json:"items"`
|
||||
}
|
||||
|
||||
type Timeline struct {
|
||||
@@ -346,6 +357,7 @@ type ImageItem struct {
|
||||
Templated bool `json:"templated"`
|
||||
HighlightID int `json:"highlight_id"`
|
||||
ClientHash string `json:"client_hash,omitempty"`
|
||||
Location Location `json:"location"`
|
||||
Type string `json:"type"`
|
||||
Links Links `json:"_links"`
|
||||
Embedded SubEmbedded `json:"_embedded"`
|
||||
|
||||
Reference in New Issue
Block a user