mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-01-07 13:55:00 +08:00
✏️ 加快 reg 处理速度
This commit is contained in:
parent
7f8d34e8a0
commit
2348039c16
@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
reg "github.com/fumiama/go-registry"
|
reg "github.com/fumiama/go-registry"
|
||||||
@ -19,8 +20,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
registry = reg.NewRegReader("reilia.eastasia.azurecontainer.io:32664", "fumiama")
|
registry = reg.NewRegReader("reilia.eastasia.azurecontainer.io:32664", "fumiama")
|
||||||
lzmu sync.Mutex
|
connmu, getmu sync.Mutex
|
||||||
|
processes sync.WaitGroup
|
||||||
|
connerr error
|
||||||
|
isconnected bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetLazyData 获取懒加载数据
|
// GetLazyData 获取懒加载数据
|
||||||
@ -32,24 +36,46 @@ func GetLazyData(path string, isReturnDataBytes, isDataMustEqual bool) ([]byte,
|
|||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var filemd5 *[16]byte
|
var filemd5 *[16]byte
|
||||||
var ms string
|
var ms string
|
||||||
|
var err error
|
||||||
|
|
||||||
u := dataurl + path[5:]
|
u := dataurl + path[5:]
|
||||||
lzmu.Lock()
|
|
||||||
logrus.Infoln("[file]检查懒加载文件:", path)
|
if !isconnected {
|
||||||
err := registry.Connect()
|
connmu.Lock()
|
||||||
if err != nil {
|
if !isconnected && connerr == nil {
|
||||||
logrus.Errorln("[file]无法连接到md5验证服务器,请自行确保下载文件的正确性:", err)
|
logrus.Infoln("[file]连接md5验证服务器...")
|
||||||
|
connerr = registry.ConnectIn(time.Second * 4)
|
||||||
|
if connerr == nil {
|
||||||
|
isconnected = true
|
||||||
|
processes.Add(1)
|
||||||
|
go func() {
|
||||||
|
processes.Wait()
|
||||||
|
_ = registry.Close()
|
||||||
|
isconnected = false
|
||||||
|
}()
|
||||||
|
} else {
|
||||||
|
logrus.Warnln("[file]连接md5验证服务器失败:", connerr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connmu.Unlock()
|
||||||
} else {
|
} else {
|
||||||
|
processes.Add(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if connerr != nil {
|
||||||
|
logrus.Warnln("[file]无法连接到md5验证服务器,请自行确保下载文件", path, "的正确性")
|
||||||
|
} else {
|
||||||
|
getmu.Lock()
|
||||||
ms, err = registry.Get(path)
|
ms, err = registry.Get(path)
|
||||||
|
getmu.Unlock()
|
||||||
|
processes.Done()
|
||||||
if err != nil || len(ms) != 16 {
|
if err != nil || len(ms) != 16 {
|
||||||
logrus.Errorln("[file]获取md5失败,请自行确保下载文件", path, "的正确性:", err)
|
logrus.Warnln("[file]获取md5失败,请自行确保下载文件", path, "的正确性:", err)
|
||||||
} else {
|
} else {
|
||||||
filemd5 = (*[16]byte)(*(*unsafe.Pointer)(unsafe.Pointer(&ms)))
|
filemd5 = (*[16]byte)(*(*unsafe.Pointer)(unsafe.Pointer(&ms)))
|
||||||
logrus.Infoln("[file]从验证服务器获得文件md5:", hex.EncodeToString(filemd5[:]))
|
logrus.Infoln("[file]从验证服务器获得文件", path, "md5:", hex.EncodeToString(filemd5[:]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = registry.Close()
|
|
||||||
lzmu.Unlock()
|
|
||||||
|
|
||||||
if IsExist(path) {
|
if IsExist(path) {
|
||||||
data, err = os.ReadFile(path)
|
data, err = os.ReadFile(path)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user