* feat: add plugin system * fix db docker build * fix hammerhead readme, add strava subscription news to docs * fixes and sdk improvements * fix: reduce Meilisearch load, debounce federation sync (#1012) * optimize meili trail index * several fixes --------- Co-authored-by: Flomp <Flomp@users.noreply.github.com> * Bump svelte from 5.55.5 to 5.56.0 in /docs (#1032) Bumps [svelte](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte) from 5.55.5 to 5.56.0. - [Release notes](https://github.com/sveltejs/svelte/releases) - [Changelog](https://github.com/sveltejs/svelte/blob/main/packages/svelte/CHANGELOG.md) - [Commits](https://github.com/sveltejs/svelte/commits/svelte@5.56.0/packages/svelte) --- updated-dependencies: - dependency-name: svelte dependency-version: 5.56.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Flomp <Flomp@users.noreply.github.com> * Release v0.19.2 (#1035) * chore: release v0.19.2 * add changelog --------- Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com> Co-authored-by: Christian Beutel <> * speed up plugin sync and several small fixes * concepts for security improvements and process stability * improve concept * security concept implemented * remove insecure TLS * worker concept implemented * fixes and cleanup * fixes * docu * mermaid, namings * WASM plugin host improvements, plugin logging * fix db migration * Improve plugin config and category mapping UI * fixes * further fixes * remove manual test sync * fix db migration and strava mapping * type added, UI improvements * fix plugin card toggle clickable area * optimize synch status card layout * plugin type 'trails' instead of 'integration' * session auth validation in UI * fix komoot date and waypoints * improve category mapping * fix send to hammerhead: trail name * plugin setup error handling improved * fix review findings * re-mapping added * rename remote_category --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Flomp <Flomp@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com>
127 lines
3.1 KiB
Go
127 lines
3.1 KiB
Go
//go:build tinygo
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
|
|
"github.com/extism/go-pdk"
|
|
)
|
|
|
|
func main() {}
|
|
|
|
//export list_routes_v1
|
|
func listRoutesV1() int32 {
|
|
var input listInput
|
|
if err := pdk.InputJSON(&input); err != nil {
|
|
return fail("invalid_request", "invalid list_routes input: "+err.Error())
|
|
}
|
|
client, err := newClient(input.Auth)
|
|
if err != nil {
|
|
return fail("auth_failed", err.Error())
|
|
}
|
|
output, err := syncRoutes(client, input)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
if err := pdk.OutputJSON(output); err != nil {
|
|
return fail("internal_error", err.Error())
|
|
}
|
|
return 0
|
|
}
|
|
|
|
//export list_activities_v1
|
|
func listActivitiesV1() int32 {
|
|
var input listInput
|
|
if err := pdk.InputJSON(&input); err != nil {
|
|
return fail("invalid_request", "invalid list_activities input: "+err.Error())
|
|
}
|
|
client, err := newClient(input.Auth)
|
|
if err != nil {
|
|
return fail("auth_failed", err.Error())
|
|
}
|
|
output, err := syncActivities(client, input)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
if err := pdk.OutputJSON(output); err != nil {
|
|
return fail("internal_error", err.Error())
|
|
}
|
|
return 0
|
|
}
|
|
|
|
//export get_route_detail_v1
|
|
func getRouteDetailV1() int32 {
|
|
return getTrailDetail("planned")
|
|
}
|
|
|
|
//export get_activity_detail_v1
|
|
func getActivityDetailV1() int32 {
|
|
return getTrailDetail("completed")
|
|
}
|
|
|
|
func getTrailDetail(kind string) int32 {
|
|
var input detailInput
|
|
if err := pdk.InputJSON(&input); err != nil {
|
|
return fail("invalid_request", "invalid detail input: "+err.Error())
|
|
}
|
|
client, err := newClient(input.Auth)
|
|
if err != nil {
|
|
return fail("auth_failed", err.Error())
|
|
}
|
|
var item trailImport
|
|
switch kind {
|
|
case "planned":
|
|
route, err := client.route(input.Summary.Source.ExternalID)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
gpxData, err := client.routeGPX(input.Summary.Source.ExternalID)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
item, err = routeImport(*route, gpxData)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
case "completed":
|
|
id, err := strconv.ParseInt(input.Summary.Source.ExternalID, 10, 64)
|
|
if err != nil {
|
|
return fail("invalid_request", "invalid activity external id")
|
|
}
|
|
detail, err := client.activity(id)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
var photos []activityPhoto
|
|
if detail.Photos.Count > 0 {
|
|
photos, _ = client.activityPhotos(id)
|
|
}
|
|
streams, err := client.activityStreams(id)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
item, err = activityImport(detail, streams, photos)
|
|
if err != nil {
|
|
return fail("provider_unavailable", err.Error())
|
|
}
|
|
default:
|
|
return fail("invalid_request", "unsupported detail kind")
|
|
}
|
|
if err := pdk.OutputJSON(detailOutput{Item: item}); err != nil {
|
|
return fail("internal_error", err.Error())
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func fail(code string, message string) int32 {
|
|
data, err := json.Marshal(pluginError{Code: code, Message: message})
|
|
if err != nil {
|
|
pdk.SetErrorString(message)
|
|
return 1
|
|
}
|
|
pdk.SetErrorString(string(data))
|
|
return 1
|
|
}
|