Overhaul [1/n]

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-01-29 02:42:28 +08:00
parent 989acd6ff1
commit c77241a883
2267 changed files with 7158 additions and 5583 deletions
+7 -15
View File
@@ -2,30 +2,22 @@ package db
import (
"fmt"
"honoka-chan/pkg/utils"
"os"
_ "modernc.org/sqlite"
"xorm.io/xorm"
)
var (
DB *Instance
Ldb *LdbInstance
ExampleDb = "assets/data.example.db"
MainDb = "assets/main.db"
UserDb = "assets/data.db"
MainEng *xorm.Engine
UserEng *xorm.Engine
MainDb = "assets/main.db"
UserDb = "assets/data.db"
MainEng *xorm.Engine
UserEng *xorm.Engine
)
func init() {
DB = GetInstance()
_, err := os.Stat(UserDb)
if err != nil {
utils.WriteAllText(UserDb, utils.ReadAllText(ExampleDb))
}
Ldb = GetLdbInstance()
eng, err := xorm.NewEngine("sqlite", MainDb)
if err != nil {
@@ -53,7 +45,7 @@ func init() {
}
func MatchTokenUid(token, uid string) bool {
res, err := DB.Get([]byte(uid))
res, err := Ldb.Get([]byte(uid))
if err != nil {
fmt.Println(err)
return false
+6 -6
View File
@@ -11,13 +11,13 @@ var (
once sync.Once
)
type Instance struct {
type LdbInstance struct {
db *leveldb.DB
mu sync.Mutex
}
func GetInstance() *Instance {
in := Instance{}
func GetLdbInstance() *LdbInstance {
in := LdbInstance{}
once.Do(func() {
var err error
in.db, err = leveldb.OpenFile("./data/honoka-chan.db", nil)
@@ -28,7 +28,7 @@ func GetInstance() *Instance {
return &in
}
func (in *Instance) Close() error {
func (in *LdbInstance) Close() error {
in.mu.Lock()
defer in.mu.Unlock()
if in.db != nil {
@@ -37,7 +37,7 @@ func (in *Instance) Close() error {
return nil
}
func (in *Instance) Get(key []byte) ([]byte, error) {
func (in *LdbInstance) Get(key []byte) ([]byte, error) {
if len(key) == 0 {
return nil, errors.New("empty key")
}
@@ -50,7 +50,7 @@ func (in *Instance) Get(key []byte) ([]byte, error) {
return res, nil
}
func (in *Instance) Set(key, value []byte) error {
func (in *LdbInstance) Set(key, value []byte) error {
if len(key) == 0 {
return errors.New("empty key")
}