Files
volumen/internal/admin/settings_update.go
petrbalvin f8ed33df83
Test / test (push) Successful in 7m5s
Release / gates (push) Successful in 7m28s
Release / build (amd64, freebsd) (push) Successful in 2m52s
Release / build (amd64, linux) (push) Successful in 2m46s
Release / build (arm64, freebsd) (push) Successful in 2m22s
Release / build (arm64, linux) (push) Successful in 2m38s
Release / build (loong64, linux) (push) Successful in 2m7s
Release / build (riscv64, linux) (push) Successful in 2m17s
Release / release (push) Successful in 1m0s
Initial commit
Assisted-by: GLM 5.3
2026-09-29 10:03:32 +02:00

57 lines
1.7 KiB
Go

// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
package admin
import (
"net/http"
)
func (a *Admin) handleSettingsCheckUpdate(w http.ResponseWriter, r *http.Request) {
if !a.requireCSRF(w, r) {
return
}
if a.deps.CheckUpdate == nil {
a.renderSettings(w, r, "", a.tr(r, "Update checks are not available in this build."), http.StatusOK)
return
}
latest, err := a.deps.CheckUpdate()
if err != nil {
a.renderSettings(w, r, a.trf(r, "Update check failed: %s", err.Error()), "", http.StatusOK)
return
}
// The hook returns "" when the running version is current, so the
// comparison has already been made by the one implementation that
// knows how to make it.
if latest == "" {
a.renderSettings(w, r, "",
a.trf(r, "volumen %s is already the latest release.", a.deps.Version), http.StatusOK)
return
}
a.renderSettings(w, r, "", a.trf(r, "volumen %s is available.", latest), http.StatusOK)
}
func (a *Admin) handleSettingsUpdate(w http.ResponseWriter, r *http.Request) {
if !a.requireCSRF(w, r) {
return
}
if a.deps.SelfUpdate == nil {
a.renderSettings(w, r, a.tr(r, "Self-update is not available in this build."), "", http.StatusUnprocessableEntity)
return
}
target, err := a.deps.SelfUpdate()
if err != nil {
message := a.trf(r, "The upgrade failed: %s", err.Error())
if target != "" {
message = a.trf2(r, "Upgrade to %s failed: %s", target, err.Error())
}
a.renderSettings(w, r, message, "", http.StatusInternalServerError)
return
}
data := a.pageData(r)
data.Target = target
a.renderPage(w, r, "update.html", data, http.StatusOK)
}
// --- webhooks and tokens ----------------------------------------------------