Drop redundant internal utils
Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -2,11 +2,11 @@ package item
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
)
|
||||
|
||||
func itemList() (res any, err error) {
|
||||
itemResp := honokautils.ReadAllText("assets/serverdata/item.json")
|
||||
itemResp := utils.ReadAllText("assets/serverdata/item.json")
|
||||
err = json.Unmarshal([]byte(itemResp), &res)
|
||||
|
||||
return res, err
|
||||
|
||||
@@ -3,13 +3,13 @@ package profile
|
||||
import (
|
||||
"encoding/json"
|
||||
profileapischema "honoka-chan/internal/schema/api/profile"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
func cardRanking() (res any, err error) {
|
||||
var result []any
|
||||
love := honokautils.ReadAllText("assets/serverdata/love.json")
|
||||
love := utils.ReadAllText("assets/serverdata/love.json")
|
||||
err = json.Unmarshal([]byte(love), &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,11 +2,11 @@ package stamp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
)
|
||||
|
||||
func stampInfo() (res any, err error) {
|
||||
stampResp := honokautils.ReadAllText("assets/serverdata/stamp.json")
|
||||
stampResp := utils.ReadAllText("assets/serverdata/stamp.json")
|
||||
err = json.Unmarshal([]byte(stampResp), &res)
|
||||
|
||||
return res, err
|
||||
|
||||
@@ -3,12 +3,12 @@ package unit
|
||||
import (
|
||||
"encoding/json"
|
||||
unitapischema "honoka-chan/internal/schema/api/unit"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
func unitAccessoryTab() (res any, err error) {
|
||||
data := honokautils.ReadAllText("assets/serverdata/accessoryTab.json")
|
||||
data := utils.ReadAllText("assets/serverdata/accessoryTab.json")
|
||||
resp := unitapischema.AccessoryTabResp{}
|
||||
err = json.Unmarshal([]byte(data), &resp)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
ghomeschema "honoka-chan/internal/schema/ghome"
|
||||
"honoka-chan/internal/session"
|
||||
"honoka-chan/pkg/encrypt"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
@@ -44,7 +44,7 @@ func handshake(ctx *gin.Context) {
|
||||
}
|
||||
ss.SetRandKey(randKey)
|
||||
|
||||
token := fmt.Sprintf(`{"message":"ok","result":0,"token":"%s"}`, strings.ToUpper(honokautils.RandomStr(33)))
|
||||
token := fmt.Sprintf(`{"message":"ok","result":0,"token":"%s"}`, strings.ToUpper(utils.RandomStr(33)))
|
||||
encryptedToken, err := openssl.Des3ECBEncrypt([]byte(token), []byte(randKey[:24]), openssl.PKCS7_PADDING)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"honoka-chan/internal/router"
|
||||
ghomeschema "honoka-chan/internal/schema/ghome"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -23,7 +23,7 @@ func publicKey(ctx *gin.Context) {
|
||||
Message: publicKeyMsg,
|
||||
}
|
||||
|
||||
publicKey := honokautils.ReadAllText(config.PublicKeyPath)
|
||||
publicKey := utils.ReadAllText(config.PublicKeyPath)
|
||||
block, _ := pem.Decode([]byte(publicKey))
|
||||
if block == nil || block.Type != "PUBLIC KEY" {
|
||||
publicKeyMsg = "公钥读取失败!"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"honoka-chan/internal/router"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -67,7 +67,7 @@ func play(ctx *gin.Context) {
|
||||
// fmt.Println("liveSetting", liveSetting)
|
||||
|
||||
notes := []liveschema.NotesList{}
|
||||
notes_list := honokautils.ReadAllText("./assets/serverdata/beatmaps/" + liveSetting.NotesSettingAsset)
|
||||
notes_list := utils.ReadAllText("./assets/serverdata/beatmaps/" + liveSetting.NotesSettingAsset)
|
||||
err = json.Unmarshal([]byte(notes_list), ¬es)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
@@ -313,7 +313,7 @@ func play(ctx *gin.Context) {
|
||||
// 好友主唱技能加成
|
||||
// TODO 好友支援存入数据库
|
||||
// var tomoUnitId int64
|
||||
// partyList := gjson.Parse(honokautils.ReadAllText("assets/serverdata/partylist.json")).Get("response_data.party_list")
|
||||
// partyList := gjson.Parse(utils.ReadAllText("assets/serverdata/partylist.json")).Get("response_data.party_list")
|
||||
// partyList.ForEach(func(key, value gjson.Result) bool {
|
||||
// if value.Get("user_info.user_id").Int() == playReq.PartyUserID {
|
||||
// tomoUnitId = value.Get("center_unit_info.unit_id").Int()
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
loginschema "honoka-chan/internal/schema/login"
|
||||
"honoka-chan/internal/session"
|
||||
"honoka-chan/pkg/encrypt"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
utils "honoka-chan/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -35,8 +35,8 @@ func authKey(ctx *gin.Context) {
|
||||
// fmt.Println(string(authDataDecrypted))
|
||||
|
||||
clientToken := base64.StdEncoding.EncodeToString(dummyTokenDecrypted)
|
||||
serverToken := base64.StdEncoding.EncodeToString([]byte(honokautils.RandomStr(32)))
|
||||
authorizeToken := base64.StdEncoding.EncodeToString([]byte(honokautils.RandomStr(32)))
|
||||
serverToken := base64.StdEncoding.EncodeToString([]byte(utils.RandomStr(32)))
|
||||
authorizeToken := base64.StdEncoding.EncodeToString([]byte(utils.RandomStr(32)))
|
||||
|
||||
ss.SetAuthKey(&loginmodel.AuthKey{
|
||||
AuthorizeToken: authorizeToken,
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
loginschema "honoka-chan/internal/schema/login"
|
||||
"honoka-chan/internal/session"
|
||||
"honoka-chan/pkg/encrypt"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -34,7 +34,7 @@ func login(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
xmcKey := honokautils.XOR(clientToken, serverToken)
|
||||
xmcKey := utils.XOR(clientToken, serverToken)
|
||||
aesKey := xmcKey[0:16]
|
||||
|
||||
reqData := gjson.Parse(ctx.MustGet("request_data").(string))
|
||||
@@ -52,7 +52,7 @@ func login(ctx *gin.Context) {
|
||||
// loginPasswd := encrypt.AESCBCDecrypt(password, aesKey)[16:]
|
||||
// fmt.Println("loginPasswd", string(loginPasswd))
|
||||
|
||||
authorizeToken := base64.StdEncoding.EncodeToString([]byte(honokautils.RandomStr(32)))
|
||||
authorizeToken := base64.StdEncoding.EncodeToString([]byte(utils.RandomStr(32)))
|
||||
|
||||
var userID int
|
||||
exists, err := ss.UserEng.Table("user_key").Where("key = ?", string(loginKey)).Cols("user_id").Get(&userID)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"honoka-chan/internal/middleware"
|
||||
"honoka-chan/internal/router"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -14,7 +14,7 @@ func reward(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
data := honokautils.ReadAllText("assets/serverdata/reward.json")
|
||||
data := utils.ReadAllText("assets/serverdata/reward.json")
|
||||
var resp map[string]any
|
||||
err := json.Unmarshal([]byte(data), &resp)
|
||||
if ss.CheckErr(err) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"honoka-chan/internal/middleware"
|
||||
"honoka-chan/internal/router"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/pkg/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -14,7 +14,7 @@ func reward(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
data := honokautils.ReadAllText("assets/serverdata/subreward.json")
|
||||
data := utils.ReadAllText("assets/serverdata/subreward.json")
|
||||
var resp map[string]any
|
||||
err := json.Unmarshal([]byte(data), &resp)
|
||||
if ss.CheckErr(err) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"honoka-chan/internal/middleware"
|
||||
"honoka-chan/internal/router"
|
||||
webuischema "honoka-chan/internal/schema/webui"
|
||||
"honoka-chan/internal/utils"
|
||||
"honoka-chan/pkg/db"
|
||||
"net/http"
|
||||
|
||||
@@ -29,8 +28,7 @@ func login(ctx *gin.Context) {
|
||||
exists, err := db.UserEng.Table("users").
|
||||
Where("phone = ? AND password = ?", user, openssl.Md5ToString(pass)).
|
||||
Cols("user_id").Get(&userId)
|
||||
utils.CheckErr(err)
|
||||
if !exists {
|
||||
if err != nil || !exists {
|
||||
ctx.JSON(http.StatusOK, webuischema.Msg{
|
||||
Code: 1,
|
||||
Message: "账号不存在或者密码有误!",
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/utils"
|
||||
"honoka-chan/pkg/db"
|
||||
"honoka-chan/pkg/encrypt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
@@ -77,6 +78,6 @@ func (ss *Session) Respond(resp any) {
|
||||
}
|
||||
|
||||
ss.Ctx.Header("Content-Type", "application/json")
|
||||
ss.Ctx.Header("X-Message-Sign", utils.GenXMS(data))
|
||||
ss.Ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSASignSHA1(data)))
|
||||
ss.Ctx.String(http.StatusOK, string(data))
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"honoka-chan/pkg/encrypt"
|
||||
)
|
||||
|
||||
func CheckErr(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func GenXMS(resp []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(encrypt.RSASignSHA1(resp))
|
||||
}
|
||||
Reference in New Issue
Block a user