mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
✏️ 增加Setu数据库自动下载
This commit is contained in:
parent
452b39075b
commit
433b0ae4c1
@ -3,6 +3,9 @@ package setutime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -28,6 +31,10 @@ type imgpool struct {
|
|||||||
Form int64
|
Form int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
dburl = "https://codechina.csdn.net/u011570312/ZeroBot-Plugin/-/raw/master/data/SetuTime/SetuTime.db"
|
||||||
|
)
|
||||||
|
|
||||||
// NewPoolsCache 返回一个缓冲池对象
|
// NewPoolsCache 返回一个缓冲池对象
|
||||||
func newPools() *imgpool {
|
func newPools() *imgpool {
|
||||||
cache := &imgpool{
|
cache := &imgpool{
|
||||||
@ -43,6 +50,24 @@ func newPools() *imgpool {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// 如果数据库不存在则下载
|
||||||
|
if _, err := os.Stat(cache.DB.DBPath); err != nil || os.IsNotExist(err) {
|
||||||
|
f, err := os.Create(cache.DB.DBPath)
|
||||||
|
if err == nil {
|
||||||
|
resp, err := http.Get(dburl)
|
||||||
|
if err == nil {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.ContentLength > 0 {
|
||||||
|
log.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength)
|
||||||
|
data, err := io.ReadAll(resp.Body)
|
||||||
|
if err == nil && len(data) > 0 {
|
||||||
|
f.Write(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
for i := range cache.List {
|
for i := range cache.List {
|
||||||
if err := cache.DB.create(cache.List[i], &pixiv.Illust{}); err != nil {
|
if err := cache.DB.create(cache.List[i], &pixiv.Illust{}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user