Implement more endpoints & overhaul [2/n]

Drop LevelDB and move all the things to SQLite.

Implemented endpoints:
/api <unit, accessoryMaterialAll>
/api <unit, accessoryTab>
/live/continue
/live/partyList
/unit/favoriteAccessory (WIP)
/unit/sale

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-04-28 11:44:56 +08:00
parent 1500821f3e
commit 150ce674ad
218 changed files with 2993 additions and 2160 deletions
-16
View File
@@ -1,15 +1,11 @@
package db
import (
"fmt"
_ "modernc.org/sqlite"
"xorm.io/xorm"
)
var (
Ldb *LdbInstance
MainDb = "assets/main.db"
UserDb = "assets/data.db"
MainEng *xorm.Engine
@@ -17,8 +13,6 @@ var (
)
func init() {
Ldb = GetLdbInstance()
eng, err := xorm.NewEngine("sqlite", MainDb)
if err != nil {
panic(err)
@@ -43,13 +37,3 @@ func init() {
eng.SetMaxIdleConns(5)
UserEng = eng
}
func MatchTokenUid(token, uid string) bool {
res, err := Ldb.Get([]byte(uid))
if err != nil {
fmt.Println(err)
return false
}
return string(res) == token
}
-58
View File
@@ -1,58 +0,0 @@
package db
import (
"errors"
"sync"
"github.com/syndtr/goleveldb/leveldb"
)
var (
once sync.Once
)
type LdbInstance struct {
db *leveldb.DB
mu sync.Mutex
}
func GetLdbInstance() *LdbInstance {
in := LdbInstance{}
once.Do(func() {
var err error
in.db, err = leveldb.OpenFile("./data/honoka-chan.db", nil)
if err != nil {
panic(err)
}
})
return &in
}
func (in *LdbInstance) Close() error {
in.mu.Lock()
defer in.mu.Unlock()
if in.db != nil {
return in.db.Close()
}
return nil
}
func (in *LdbInstance) Get(key []byte) ([]byte, error) {
if len(key) == 0 {
return nil, errors.New("empty key")
}
res, err := in.db.Get(key, nil)
if err == leveldb.ErrNotFound {
return nil, nil
} else if err != nil {
return nil, err
}
return res, nil
}
func (in *LdbInstance) Set(key, value []byte) error {
if len(key) == 0 {
return errors.New("empty key")
}
return in.db.Put(key, value, nil)
}