diff --git a/ui/api.go b/ui/api.go new file mode 100644 index 00000000..e1f10d9a --- /dev/null +++ b/ui/api.go @@ -0,0 +1,33 @@ +package ui + +import ( + resources "github.com/cookieo9/resources-go" + "github.com/safing/portbase/api" + "github.com/safing/portbase/log" +) + +func registerAPIEndpoints() error { + return api.RegisterEndpoint(api.Endpoint{ + Path: "ui/reload", + Read: api.PermitUser, + ActionFunc: reloadUI, + }) +} + +func reloadUI(_ *api.Request) (msg string, err error) { + appsLock.Lock() + defer appsLock.Unlock() + + // close all bundles. + for id, bundle := range apps { + err := bundle.Close() + if err != nil { + log.Warningf("ui: failed to close bundle %s: %s", id, err) + } + } + + // Reset index. + apps = make(map[string]*resources.BundleSequence) + + return "all ui bundles successfully reloaded", nil +} diff --git a/updates/api.go b/updates/api.go new file mode 100644 index 00000000..c6aa2719 --- /dev/null +++ b/updates/api.go @@ -0,0 +1,24 @@ +package updates + +import ( + "github.com/safing/portbase/api" +) + +const ( + apiPathCheckForUpdates = "updates/check" +) + +func registerAPIEndpoints() error { + return api.RegisterEndpoint(api.Endpoint{ + Path: apiPathCheckForUpdates, + Read: api.PermitUser, + ActionFunc: func(_ *api.Request) (msg string, err error) { + if err := TriggerUpdate(); err != nil { + return "", err + } + return "triggered update check", nil + }, + Name: "Check for Updates", + Description: "Triggers checking for updates.", + }) +}