mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
Refactor site configuration and color scheme management
- Replaced static config with dynamic site info context. - Updated color scheme handling in various components to use site info. - Removed deprecated config file and integrated site info fetching. - Enhanced user preference page to allow color scheme selection. - Adjusted blog and console components to reflect new site info structure. - Improved error handling and fallback mechanisms for site info retrieval.
This commit is contained in:
@ -129,6 +129,7 @@ func migrate() error {
|
||||
&model.Label{},
|
||||
&model.Like{},
|
||||
&model.File{},
|
||||
&model.KV{},
|
||||
&model.OidcConfig{},
|
||||
&model.Post{},
|
||||
&model.Session{},
|
||||
|
@ -1,5 +1,50 @@
|
||||
package main
|
||||
package repo
|
||||
|
||||
func main() {
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/snowykami/neo-blog/internal/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type kvRepo struct{}
|
||||
|
||||
var KV = &kvRepo{}
|
||||
|
||||
func (k *kvRepo) GetKV(key string, defaultValue ...any) (any, error) {
|
||||
var kv = &model.KV{}
|
||||
err := GetDB().First(kv, "key = ?", key).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
if len(defaultValue) > 0 {
|
||||
return defaultValue[0], nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if kv.Value == nil {
|
||||
if len(defaultValue) > 0 {
|
||||
return defaultValue[0], nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if v, ok := kv.Value["value"]; ok {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
if len(defaultValue) > 0 {
|
||||
return defaultValue[0], nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (k *kvRepo) SetKV(key string, value any) error {
|
||||
kv := &model.KV{
|
||||
Key: key,
|
||||
Value: map[string]any{"value": value},
|
||||
}
|
||||
return GetDB().Save(kv).Error
|
||||
}
|
||||
|
@ -1 +1,18 @@
|
||||
package repo
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestKvRepo_GetKV(t *testing.T) {
|
||||
err := KV.SetKV("AAA", map[string]interface{}{"b": 1, "c": "2"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v, _ := KV.GetKV("AAA")
|
||||
t.Log(v)
|
||||
if v.(map[string]interface{})["b"] != float64(1) {
|
||||
t.Fatal("b not equal")
|
||||
}
|
||||
if v.(map[string]interface{})["c"] != "2" {
|
||||
t.Fatal("c not equal")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user