mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
🎨 改进结构
This commit is contained in:
parent
19f58acb79
commit
085e04c9ba
@ -58,23 +58,36 @@ func newPools() *imgpool {
|
|||||||
}
|
}
|
||||||
// 如果数据库不存在则下载
|
// 如果数据库不存在则下载
|
||||||
if _, err := os.Stat(cache.DB.DBPath); err != nil || os.IsNotExist(err) {
|
if _, err := os.Stat(cache.DB.DBPath); err != nil || os.IsNotExist(err) {
|
||||||
f, err := os.Create(cache.DB.DBPath)
|
down := func() (err error) {
|
||||||
if err == nil {
|
// 下载
|
||||||
resp, err := http.Get(dburl)
|
resp, err := http.Get(dburl)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.ContentLength > 0 {
|
if resp.ContentLength > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
logrus.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength)
|
logrus.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength)
|
||||||
data, err := io.ReadAll(resp.Body)
|
// 生成文件
|
||||||
if err == nil && len(data) > 0 {
|
f, err := os.Create(cache.DB.DBPath)
|
||||||
_, err = f.Write(data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("[Setu]写入数据库失败: %v", err)
|
return
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
// 读取数据
|
||||||
|
data, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil || len(data) > 0 {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
// 写入数据
|
||||||
|
if _, err = f.Write(data); err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
f.Close()
|
if err := down(); err != nil {
|
||||||
|
logrus.Printf("[Setu]下载数据库失败%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range cache.List {
|
for i := range cache.List {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user