节点自动升级功能之前的版本

This commit is contained in:
robin
2026-03-02 23:42:55 +08:00
parent 2a76d1773d
commit 853897a6f8
29 changed files with 1063 additions and 81 deletions

View File

@@ -15,8 +15,9 @@ var SharedDeployManager = NewDeployManager()
type DeployManager struct {
dir string
nodeFiles []*DeployFile
nsNodeFiles []*DeployFile
nodeFiles []*DeployFile
nsNodeFiles []*DeployFile
httpdnsNodeFiles []*DeployFile
locker sync.Mutex
}
@@ -28,6 +29,7 @@ func NewDeployManager() *DeployManager {
}
manager.LoadNodeFiles()
manager.LoadNSNodeFiles()
manager.LoadHTTPDNSNodeFiles()
return manager
}
@@ -141,6 +143,61 @@ func (this *DeployManager) FindNSNodeFile(os string, arch string) *DeployFile {
return nil
}
// LoadHTTPDNSNodeFiles 加载所有HTTPDNS节点安装文件
func (this *DeployManager) LoadHTTPDNSNodeFiles() []*DeployFile {
this.locker.Lock()
defer this.locker.Unlock()
if len(this.httpdnsNodeFiles) > 0 {
return this.httpdnsNodeFiles
}
var keyMap = map[string]*DeployFile{} // key => File
var reg = regexp.MustCompile(`^edge-httpdns-(\w+)-(\w+)-v([0-9.]+)\.zip$`)
for _, file := range files.NewFile(this.dir).List() {
var name = file.Name()
if !reg.MatchString(name) {
continue
}
var matches = reg.FindStringSubmatch(name)
var osName = matches[1]
var arch = matches[2]
var version = matches[3]
var key = osName + "_" + arch
oldFile, ok := keyMap[key]
if ok && stringutil.VersionCompare(oldFile.Version, version) > 0 {
continue
}
keyMap[key] = &DeployFile{
OS: osName,
Arch: arch,
Version: version,
Path: file.Path(),
}
}
var result = []*DeployFile{}
for _, v := range keyMap {
result = append(result, v)
}
this.httpdnsNodeFiles = result
return result
}
// FindHTTPDNSNodeFile 查找特定平台的HTTPDNS节点安装文件
func (this *DeployManager) FindHTTPDNSNodeFile(os string, arch string) *DeployFile {
for _, file := range this.LoadHTTPDNSNodeFiles() {
if file.OS == os && file.Arch == arch {
return file
}
}
return nil
}
// Reload 重置缓存
func (this *DeployManager) Reload() {
this.locker.Lock()
@@ -148,4 +205,5 @@ func (this *DeployManager) Reload() {
this.nodeFiles = nil
this.nsNodeFiles = nil
this.httpdnsNodeFiles = nil
}