x
This commit is contained in:
@@ -8,6 +8,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="/admin/umi.14fdd3e9.js"></script>
|
||||
<script src="/admin/umi.dd41d0dd.js"></script>
|
||||
|
||||
</body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+72
-18
@@ -1,11 +1,11 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cdle/sillyplus/core/logs"
|
||||
"github.com/cdle/sillyplus/core/storage"
|
||||
@@ -19,33 +19,86 @@ var bkt storage.Bucket
|
||||
var HttpPort string
|
||||
var sillyGirl = MakeBucket("sillyGirl")
|
||||
|
||||
var Get = func(key string) string {
|
||||
return ""
|
||||
}
|
||||
var Set = func(key, value string, expiration time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
// var Get = func(key string) string {
|
||||
// return ""
|
||||
// }
|
||||
// var Set = func(key, value string, expiration time.Duration) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
var MakeBucketlocker sync.Mutex
|
||||
var app storage.Bucket
|
||||
|
||||
func MakeBucket(name string) storage.Bucket {
|
||||
MakeBucketlocker.Lock()
|
||||
defer MakeBucketlocker.Unlock()
|
||||
if bkt == nil {
|
||||
// utils.ReadYaml(utils.ExecPath+"/conf/", &Config, "https://raw.githubusercontent.com/cdle/sillyplus/main/conf/demo_config.yaml")
|
||||
utils.SlaveMode = Config.SlaveMode
|
||||
HttpPort = Config.HttpPort
|
||||
if !Config.EnableRedis {
|
||||
bkt = boltdb.Initsillyplus()
|
||||
Get = boltdb.Get
|
||||
Set = boltdb.Set
|
||||
logs.Info("默认使用boltdb进行数据存储")
|
||||
// if !Config.EnableRedis {
|
||||
bkt = boltdb.Initsillyplus()
|
||||
// Get = boltdb.Get
|
||||
// Set = boltdb.Set
|
||||
// logs.Info("默认使用boltdb进行数据存储")
|
||||
// } else {
|
||||
// bkt = redis.Initsillyplus(Config.RedisAddr, Config.RedisPassword)
|
||||
// Get = redis.Get
|
||||
// Set = redis.Set
|
||||
// logs.Info("已使用redis进行数据存储")
|
||||
// }
|
||||
app = bkt
|
||||
if def := bkt.GetString("storage"); def == "redis" {
|
||||
func() {
|
||||
defer func() {
|
||||
err := recover()
|
||||
if err != nil {
|
||||
// console.Warn("redis异常,已默认启用boltdb进行数据存储")
|
||||
bkt = app
|
||||
}
|
||||
}()
|
||||
bkt = redis.Initsillyplus(app.GetString("redis_addr"), app.GetString("redis_password"))
|
||||
bkt.Set("storage", "redis")
|
||||
|
||||
}()
|
||||
} else {
|
||||
bkt = redis.Initsillyplus(Config.RedisAddr, Config.RedisPassword)
|
||||
Get = redis.Get
|
||||
Set = redis.Set
|
||||
logs.Info("已使用redis进行数据存储")
|
||||
if def != "boltdb" {
|
||||
bkt.Set("storage", "boltdb")
|
||||
}
|
||||
logs.Info("默认使用boltdb进行数据存储")
|
||||
}
|
||||
|
||||
storage.Watch(app, "storage", func(old, new, _ string) *storage.Final {
|
||||
if new != "redis" {
|
||||
return nil
|
||||
}
|
||||
message := "Redis连接成功,重启生效!"
|
||||
err := redis.Try(app.GetString("redis_addr"), app.GetString("redis_password"))
|
||||
if err != nil {
|
||||
message = "Redis连接失败,操作无效:" + err.Error()
|
||||
}
|
||||
return &storage.Final{
|
||||
Error: errors.New(message),
|
||||
}
|
||||
})
|
||||
storage.Watch(app, "redis_addr", func(old, new, _ string) *storage.Final {
|
||||
message := "Redis连接成功,重启生效!"
|
||||
err := redis.Try(app.GetString("redis_addr"), app.GetString("redis_password"))
|
||||
if err != nil {
|
||||
message = "Redis连接失败:" + err.Error()
|
||||
}
|
||||
return &storage.Final{
|
||||
Message: message,
|
||||
}
|
||||
})
|
||||
storage.Watch(app, "redis_password", func(old, new, _ string) *storage.Final {
|
||||
message := "Redis连接成功,重启生效!"
|
||||
err := redis.Try(app.GetString("redis_addr"), app.GetString("redis_password"))
|
||||
if err != nil {
|
||||
message = "Redis连接失败:" + err.Error()
|
||||
}
|
||||
return &storage.Final{
|
||||
Message: message,
|
||||
}
|
||||
})
|
||||
for _, name := range bkt.Buckets() {
|
||||
b := bkt.Copy(name)
|
||||
keys, err := b.Keys()
|
||||
@@ -53,6 +106,7 @@ func MakeBucket(name string) storage.Bucket {
|
||||
b.Delete()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if name == "" {
|
||||
name = "sillyGirl"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package core
|
||||
|
||||
type Yaml struct {
|
||||
EnableRedis bool `yaml:"enable_redis"`
|
||||
RedisAddr string `yaml:"redis_addr"`
|
||||
RedisPassword string `yaml:"redis_password"`
|
||||
SlaveMode bool `yaml:"slave_mode"`
|
||||
HttpPort string `yaml:"http_port"`
|
||||
}
|
||||
|
||||
var Config Yaml
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
var DataHome = utils.GetDataHome()
|
||||
|
||||
func Init() {
|
||||
|
||||
sillyGirl = MakeBucket("sillyGirl")
|
||||
_, err := os.Stat(DataHome)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,6 +23,7 @@ type RequestPluginResult struct {
|
||||
Total int `json:"total"`
|
||||
Tab1 int `json:"tab1"`
|
||||
Tab2 int `json:"tab2"`
|
||||
Tab3 int `json:"tab3"`
|
||||
Time time.Time `json:"time"`
|
||||
}
|
||||
|
||||
@@ -145,30 +146,50 @@ func initWebPluginList() {
|
||||
rr.Total = len(list)
|
||||
tab1 := []*common.Function{}
|
||||
tab2 := []*common.Function{}
|
||||
tab3 := []*common.Function{}
|
||||
fc := []*common.Function{}
|
||||
fc = append(fc, Functions...)
|
||||
for i := range list {
|
||||
ded := false
|
||||
for j := range fc {
|
||||
if list[i].UUID == fc[j].UUID {
|
||||
// v1, err1 := version.NewVersion(list[i].Version)
|
||||
// v2, err2 := version.NewVersion(fc[j].Version)
|
||||
// if err1 == nil && err2 == nil {
|
||||
// if v2.Compare(v1) > 0 {
|
||||
// tab3 = append(tab3, list[i])
|
||||
// }
|
||||
// } else if err1 != nil && err2 != nil {
|
||||
// tab3 = append(tab3, list[i])
|
||||
// }
|
||||
if list[i].Version != fc[j].Version {
|
||||
tab3 = append(tab3, list[i])
|
||||
}
|
||||
ded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if ded {
|
||||
tab1 = append(tab1, list[i])
|
||||
tab1 = append(tab1, list[i]) //已安装
|
||||
} else {
|
||||
tab2 = append(tab2, list[i])
|
||||
}
|
||||
}
|
||||
if activeKey != "tab2" {
|
||||
list = tab1
|
||||
rr.Tab1 = len(list)
|
||||
rr.Tab2 = rr.Total - len(list)
|
||||
} else {
|
||||
if activeKey == "tab2" {
|
||||
list = tab2
|
||||
rr.Tab2 = len(list)
|
||||
rr.Tab1 = rr.Total - len(list)
|
||||
rr.Tab1 = len(tab1)
|
||||
rr.Tab2 = len(tab2)
|
||||
rr.Tab3 = len(tab3)
|
||||
} else if activeKey == "tab3" {
|
||||
list = tab3
|
||||
rr.Tab1 = len(tab1)
|
||||
rr.Tab2 = len(tab2)
|
||||
rr.Tab3 = len(tab3)
|
||||
} else {
|
||||
list = tab1
|
||||
rr.Tab1 = len(tab1)
|
||||
rr.Tab2 = len(tab2)
|
||||
rr.Tab3 = len(tab3)
|
||||
}
|
||||
rr.Total = len(list)
|
||||
begin := (current - 1) * pageSize
|
||||
|
||||
@@ -72,7 +72,7 @@ func Initsillyplus() storage.Bucket {
|
||||
}
|
||||
|
||||
v := &Bucket{
|
||||
name: "sillyplus",
|
||||
name: "sillyGirl",
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/cdle/sillyplus/core/logs"
|
||||
"github.com/cdle/sillyplus/core/storage"
|
||||
"github.com/cdle/sillyplus/utils"
|
||||
|
||||
@@ -69,18 +70,37 @@ func (bucket *Bucket) Type() string {
|
||||
return "redis"
|
||||
}
|
||||
|
||||
func Try(RedisAddr, RedisPassword string) error {
|
||||
db := redis.NewClient(&redis.Options{
|
||||
Addr: RedisAddr,
|
||||
Password: RedisPassword, // no password set
|
||||
DB: 0, // use default DB
|
||||
DialTimeout: time.Second * 5,
|
||||
})
|
||||
err := db.Get(context.Background(), "666").Err()
|
||||
if err == nil {
|
||||
db.Close()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func Initsillyplus(RedisAddr, RedisPassword string) storage.Bucket {
|
||||
db = redis.NewClient(&redis.Options{
|
||||
Addr: RedisAddr,
|
||||
Password: RedisPassword, // no password set
|
||||
DB: 0, // use default DB
|
||||
Addr: RedisAddr,
|
||||
Password: RedisPassword, // no password set
|
||||
DB: 0, // use default DB
|
||||
DialTimeout: time.Second * 5,
|
||||
})
|
||||
if db == nil {
|
||||
panic("redis is not ok")
|
||||
|
||||
err := db.Get(context.Background(), "666").Err()
|
||||
if err != nil {
|
||||
logs.Error("redis错误", err)
|
||||
panic(err)
|
||||
}
|
||||
sillyplus = &Bucket{
|
||||
name: "sillyplus",
|
||||
name: "sillyGirl",
|
||||
}
|
||||
|
||||
port := sillyplus.GetString("port", "8080")
|
||||
if utils.SlaveMode {
|
||||
is, _ := db.ConfigGet(ctx, "slaveof").Result()
|
||||
|
||||
Reference in New Issue
Block a user