* 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>
73 lines
2.4 KiB
Go
73 lines
2.4 KiB
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/pocketbase/pocketbase/apis"
|
|
"github.com/pocketbase/pocketbase/core"
|
|
|
|
"pocketbase/pluginsystem"
|
|
)
|
|
|
|
// PluginSystemPluginsList refreshes the installed plugin cache and returns the
|
|
// plugins that are available from the local runtime directory.
|
|
func PluginSystemPluginsList(e *core.RequestEvent) error {
|
|
if e.Auth == nil && !e.HasSuperuserAuth() {
|
|
return apis.NewUnauthorizedError("authentication required", nil)
|
|
}
|
|
|
|
manager := pluginsystem.NewManager(e.App, "")
|
|
if err := manager.SyncInstalledPlugins(e.Request.Context()); err != nil {
|
|
return err
|
|
}
|
|
plugins, err := manager.ListLocalPlugins(e.Request.Context())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !e.HasSuperuserAuth() {
|
|
for i := range plugins {
|
|
plugins[i].Path = ""
|
|
}
|
|
}
|
|
|
|
return e.JSON(http.StatusOK, map[string]any{"items": plugins})
|
|
}
|
|
|
|
// localPlugin resolves an installed plugin from the cached installed_plugins
|
|
// record, with disk manifest fallback handled inside pluginsystem.
|
|
func localPlugin(app core.App, pluginID string) (pluginsystem.LocalPlugin, error) {
|
|
plugin, err := pluginsystem.LoadInstalledPlugin(app, "", pluginID)
|
|
if err != nil {
|
|
return pluginsystem.LocalPlugin{}, apis.NewBadRequestError("unknown plugin", err)
|
|
}
|
|
return plugin, nil
|
|
}
|
|
|
|
// pluginCapability returns the manifest entry for a concrete capability/version
|
|
// pair so the host can call the export declared by the plugin.
|
|
func pluginCapability(plugin pluginsystem.LocalPlugin, name string, version string) (pluginsystem.CapabilityManifest, error) {
|
|
for _, capability := range plugin.Manifest.Capabilities {
|
|
if capability.Name == name && capability.Version == version {
|
|
return capability, nil
|
|
}
|
|
}
|
|
return pluginsystem.CapabilityManifest{}, apis.NewBadRequestError("plugin capability is not available", map[string]string{
|
|
"name": name,
|
|
"version": version,
|
|
})
|
|
}
|
|
|
|
// localPluginCapability resolves an installed plugin and verifies that it
|
|
// declares the requested capability.
|
|
func localPluginCapability(app core.App, pluginID string, name string, version string) (pluginsystem.LocalPlugin, pluginsystem.CapabilityManifest, error) {
|
|
plugin, err := localPlugin(app, pluginID)
|
|
if err != nil {
|
|
return pluginsystem.LocalPlugin{}, pluginsystem.CapabilityManifest{}, err
|
|
}
|
|
capability, err := pluginCapability(plugin, name, version)
|
|
if err != nil {
|
|
return pluginsystem.LocalPlugin{}, pluginsystem.CapabilityManifest{}, err
|
|
}
|
|
return plugin, capability, nil
|
|
}
|