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:
@@ -2,8 +2,7 @@ package session
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"honoka-chan/internal/model/user"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/utils"
|
||||
"honoka-chan/pkg/db"
|
||||
"log"
|
||||
@@ -19,7 +18,7 @@ type Session struct {
|
||||
UserEng *xorm.Session
|
||||
|
||||
UserID int
|
||||
UserPref user.UserPref
|
||||
UserPref usermodel.UserPref
|
||||
}
|
||||
|
||||
func New(ctx *gin.Context) *Session {
|
||||
@@ -33,14 +32,7 @@ func New(ctx *gin.Context) *Session {
|
||||
|
||||
userID := ctx.GetString("userid")
|
||||
if userID != "" {
|
||||
exist, err := ss.UserEng.Table("user_pref").Where("user_id = ?", userID).Get(&ss.UserPref)
|
||||
if ss.CheckErr(err) {
|
||||
return nil
|
||||
}
|
||||
if !exist {
|
||||
ss.Abort(errors.New("user not exist!"))
|
||||
return nil
|
||||
}
|
||||
ss.UserPref = ss.GetUserPref(userID)
|
||||
ss.UserID = ss.UserPref.UserID
|
||||
}
|
||||
|
||||
@@ -77,18 +69,6 @@ func (ss *Session) CheckErr(err error) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (ss *Session) GetDeviceID() string {
|
||||
return ss.Ctx.Request.Header.Get("X-DEVICEID")
|
||||
}
|
||||
|
||||
func (ss *Session) GetRandKey() []byte {
|
||||
key, err := db.Ldb.Get([]byte(ss.GetDeviceID()))
|
||||
if ss.CheckErr(err) {
|
||||
return nil
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
func (ss *Session) Respond(resp any) {
|
||||
data, err := json.Marshal(resp)
|
||||
if ss.CheckErr(err) {
|
||||
|
||||
Reference in New Issue
Block a user