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) {
|
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())
|
body, err := sendRequest(url, k.buildHeader())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -234,9 +234,18 @@ func createTrailFromTour(app *pocketbase.PocketBase, detailedTour *DetailedKomoo
|
|||||||
categoryId = category.Id
|
categoryId = category.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
photo, err := fetchPhoto(detailedTour.MapImage.Src, "", "")
|
var photos []*filesystem.File
|
||||||
if err != nil {
|
if len(detailedTour.Embedded.CoverImages.Embedded.Items) > 0 {
|
||||||
return err
|
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
|
diffculty := detailedTour.Difficulty.Grade
|
||||||
@@ -262,7 +271,9 @@ func createTrailFromTour(app *pocketbase.PocketBase, detailedTour *DetailedKomoo
|
|||||||
"author": user,
|
"author": user,
|
||||||
})
|
})
|
||||||
|
|
||||||
form.AddFiles("photos", photo)
|
for _, photo := range photos {
|
||||||
|
form.AddFiles("photos", photo)
|
||||||
|
}
|
||||||
form.AddFiles("gpx", gpx)
|
form.AddFiles("gpx", gpx)
|
||||||
|
|
||||||
if err := form.Submit(); err != nil {
|
if err := form.Submit(); err != nil {
|
||||||
@@ -327,6 +338,23 @@ func createWaypointsFromTour(app *pocketbase.PocketBase, tour *DetailedKomootTou
|
|||||||
return wpIds, nil
|
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) {
|
func fetchWaypointPhotos(wp Item) ([]*filesystem.File, error) {
|
||||||
|
|
||||||
photos := make([]*filesystem.File, len(wp.Embedded.Reference.Embedded.Images.Embedded.Items))
|
photos := make([]*filesystem.File, len(wp.Embedded.Reference.Embedded.Images.Embedded.Items))
|
||||||
|
|||||||
@@ -246,6 +246,17 @@ type Coordinates struct {
|
|||||||
type DetailedTourEmbedded struct {
|
type DetailedTourEmbedded struct {
|
||||||
Coordinates Coordinates `json:"coordinates"`
|
Coordinates Coordinates `json:"coordinates"`
|
||||||
Timeline Timeline `json:"timeline"`
|
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 {
|
type Timeline struct {
|
||||||
@@ -346,6 +357,7 @@ type ImageItem struct {
|
|||||||
Templated bool `json:"templated"`
|
Templated bool `json:"templated"`
|
||||||
HighlightID int `json:"highlight_id"`
|
HighlightID int `json:"highlight_id"`
|
||||||
ClientHash string `json:"client_hash,omitempty"`
|
ClientHash string `json:"client_hash,omitempty"`
|
||||||
|
Location Location `json:"location"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Links Links `json:"_links"`
|
Links Links `json:"_links"`
|
||||||
Embedded SubEmbedded `json:"_embedded"`
|
Embedded SubEmbedded `json:"_embedded"`
|
||||||
|
|||||||
Reference in New Issue
Block a user