@@ -190,17 +190,67 @@ func syncTrailMetadata(app core.App, record *core.Record, data map[string]any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve Tags
|
||||||
|
localTagIds := resolveAndSyncTags(app, data)
|
||||||
|
if len(localTagIds) > 0 {
|
||||||
|
record.Set("tags", localTagIds)
|
||||||
|
}
|
||||||
|
|
||||||
// Clean protected/complex fields before bulk load
|
// Clean protected/complex fields before bulk load
|
||||||
delete(data, "id")
|
delete(data, "id")
|
||||||
delete(data, "photos")
|
delete(data, "photos")
|
||||||
delete(data, "gpx")
|
delete(data, "gpx")
|
||||||
delete(data, "author")
|
delete(data, "author")
|
||||||
delete(data, "category")
|
delete(data, "category")
|
||||||
|
delete(data, "tags")
|
||||||
delete(data, "iri")
|
delete(data, "iri")
|
||||||
|
|
||||||
record.Load(data)
|
record.Load(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resolveAndSyncTags(app core.App, data map[string]any) []string {
|
||||||
|
var localTagIds []string
|
||||||
|
|
||||||
|
expand, ok := data["expand"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
return localTagIds
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteTags, ok := expand["tags"].([]any)
|
||||||
|
if !ok {
|
||||||
|
return localTagIds
|
||||||
|
}
|
||||||
|
|
||||||
|
tagCol, _ := app.FindCollectionByNameOrId("tags")
|
||||||
|
|
||||||
|
for _, t := range remoteTags {
|
||||||
|
tagMap, ok := t.(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
tagName, _ := tagMap["name"].(string)
|
||||||
|
if tagName == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
localTag, _ := app.FindFirstRecordByData("tags", "name", tagName)
|
||||||
|
|
||||||
|
if localTag == nil {
|
||||||
|
localTag = core.NewRecord(tagCol)
|
||||||
|
localTag.Set("name", tagName)
|
||||||
|
|
||||||
|
if err := app.Save(localTag); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
localTagIds = append(localTagIds, localTag.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localTagIds
|
||||||
|
}
|
||||||
|
|
||||||
func syncWaypoints(txApp core.App, ctx context.Context, trail *core.Record, origin string, waypoints []any) error {
|
func syncWaypoints(txApp core.App, ctx context.Context, trail *core.Record, origin string, waypoints []any) error {
|
||||||
col, _ := txApp.FindCollectionByNameOrId("waypoints")
|
col, _ := txApp.FindCollectionByNameOrId("waypoints")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user