Fix and improve triggering updates from UI
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/safing/portbase/api"
|
||||
)
|
||||
|
||||
@@ -10,16 +12,32 @@ const (
|
||||
|
||||
func registerAPIEndpoints() error {
|
||||
return api.RegisterEndpoint(api.Endpoint{
|
||||
Name: "Check for Updates",
|
||||
Description: "Checks if new versions are available. If automatic updates are enabled, they are also downloaded and applied.",
|
||||
Parameters: []api.Parameter{{
|
||||
Method: http.MethodPost,
|
||||
Field: "download",
|
||||
Value: "",
|
||||
Description: "Force downloading and applying of all updates, regardless of auto-update settings.",
|
||||
}},
|
||||
Path: apiPathCheckForUpdates,
|
||||
Write: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
ActionFunc: func(_ *api.Request) (msg string, err error) {
|
||||
if err := TriggerUpdate(false); err != nil {
|
||||
ActionFunc: func(r *api.Request) (msg string, err error) {
|
||||
// Check if we should also download regardless of settings.
|
||||
downloadAll := r.URL.Query().Has("download")
|
||||
|
||||
// Trigger update task.
|
||||
err = TriggerUpdate(true, downloadAll)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "triggered update check", nil
|
||||
|
||||
// Report how we triggered.
|
||||
if downloadAll {
|
||||
return "downloading all updates...", nil
|
||||
}
|
||||
return "checking for updates...", nil
|
||||
},
|
||||
Name: "Check for Updates",
|
||||
Description: "Checks if new versions are available and downloads and applies them, if automatic updates are enabled.",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user