feat: Настройки › Автообновление - clients compare their version with the server's every N and update themselves; the server looks at GitLab every N and, when a newer release is out, offers it to an administrator at login (after the PIN) with «Обновить» and «Отказаться»; the words of a made picture's result are the model's only

This commit is contained in:
redtea committed 2026-10-18 12:33:24 +03:00
1 parent 916a49958b
commit 3d2f886f04
22 files changed
+1074 -7

No files matched your search

+11
View File
@@ -103,8 +103,19 @@ type WSMsg struct {
Transport string `json:"transport,omitempty"`
Fallback string `json:"fallback,omitempty"`
Main string `json:"main,omitempty"`
// Auto-update of agents: how often (minutes) an agent compares its
// version with the server's and updates itself if the server's is newer;
// 0 or missing - it does not. ServerVersion is the server's.
AutoUpdate int `json:"autoupdate,omitempty"`
ServerVersion string `json:"server_version,omitempty"`
}
// Headers with the same on the poll answer and on /api/agent/config.
const (
AutoUpdateHeader = "X-Auto-Update" // minutes, "0" or missing: off
ServerVersionHeader = "X-Server-Version" // the server's release version
)
// Terminal / stream frame types on the session "in" channel (server -> agent).
// Reused for both PTY terminals and raw TCP port-forward streams.
const (
+50
View File
@@ -0,0 +1,50 @@
package proto
import (
"strconv"
"strings"
)
// versionParts reads "0.2.5" (a leading v and a "-suffix" are allowed) as
// numbers; ok is false for anything that is not a dotted number.
func versionParts(v string) (parts []int, ok bool) {
v = strings.TrimPrefix(strings.TrimSpace(v), "v")
if i := strings.IndexAny(v, "-+"); i >= 0 {
v = v[:i]
}
if v == "" {
return nil, false
}
for _, p := range strings.Split(v, ".") {
n, err := strconv.Atoi(p)
if err != nil || n < 0 {
return nil, false
}
parts = append(parts, n)
}
return parts, true
}
// VersionNewer reports whether version a is higher than b. Anything that is
// not a dotted number (a build named "dev", an empty string) is never newer
// and never older - so a program is never "updated" down, or from a guess.
func VersionNewer(a, b string) bool {
pa, okA := versionParts(a)
pb, okB := versionParts(b)
if !okA || !okB {
return false
}
for i := 0; i < len(pa) || i < len(pb); i++ {
var x, y int
if i < len(pa) {
x = pa[i]
}
if i < len(pb) {
y = pb[i]
}
if x != y {
return x > y
}
}
return false
}
+30
View File
@@ -0,0 +1,30 @@
package proto
import "testing"
// A version is newer only when it is a higher dotted number: never for the
// same, an older one, or what is not a version at all.
func TestVersionNewer(t *testing.T) {
for _, c := range []struct {
a, b string
want bool
}{
{"0.2.5", "0.2.4", true},
{"0.2.10", "0.2.9", true},
{"0.3.0", "0.2.99", true},
{"1.0", "0.9.9", true},
{"0.2.4", "0.2.4", false},
{"0.2.3", "0.2.4", false},
{"0.2", "0.2.0", false},
{"v0.2.5", "0.2.4", true},
{"", "0.2.4", false},
{"dev", "0.2.4", false},
{"0.2.5", "dev", false},
{"0.2.5", "", false},
{"0.2.5-rc1", "0.2.4", true},
} {
if got := VersionNewer(c.a, c.b); got != c.want {
t.Errorf("VersionNewer(%q, %q) = %v, want %v", c.a, c.b, got, c.want)
}
}
}