mirror of
https://github.com/safing/portmaster
synced 2025-09-07 04:59:16 +00:00
Add api endpoints for UI
This commit is contained in:
parent
2a7347899c
commit
723809563c
2 changed files with 57 additions and 0 deletions
33
ui/api.go
Normal file
33
ui/api.go
Normal file
|
@ -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
|
||||||
|
}
|
24
updates/api.go
Normal file
24
updates/api.go
Normal file
|
@ -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.",
|
||||||
|
})
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue