sif: Make some user/ui preferences configurable

people wants to change them

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2024-01-27 05:12:35 +08:00
parent a6fe2e7740
commit 09f0237560
3 changed files with 53 additions and 16 deletions
+26 -2
View File
@@ -9,8 +9,9 @@ import (
)
type AppConfigs struct {
AppName string `json:"app_name"`
Settings Settings `json:"settings"`
AppName string `json:"app_name"`
Settings Settings `json:"settings"`
UserPrefs UserPrefs `json:"user_prefs"`
}
type Settings struct {
@@ -18,6 +19,18 @@ type Settings struct {
AsCdnServer string `json:"as_cdn_server"`
}
type UserPrefs struct {
Name string `json:"name"` // 用户名
Level int `json:"level"` // 用户等级
ExpNumerator int `json:"exp_numerator"` // Exp 分子
ExpDenominator int `json:"exp_denominator"` // Exp 分母
GameCoin int `json:"game_coin"` // 游戏金币
SnsCoin int `json:"sns_coin"` // 游戏爱心
EnergyMax int `json:"energy_max"` // 体力上限
OverMaxEnergy int `json:"over_max_energy"` // 实际体力,为 0 时与 EnergyMax 一致
InviteCode string `json:"invite_code"` // 用户 ID
}
func DefaultConfigs() *AppConfigs {
return &AppConfigs{
AppName: "honoka-chan",
@@ -25,6 +38,17 @@ func DefaultConfigs() *AppConfigs {
SifCdnServer: "http://192.168.1.123/static",
AsCdnServer: "http://192.168.1.123/static",
},
UserPrefs: UserPrefs{
Name: "梦路 @bilibili",
Level: 1028,
ExpNumerator: 1089696,
ExpDenominator: 1207185,
GameCoin: 112124104,
SnsCoin: 0,
EnergyMax: 417,
OverMaxEnergy: 0,
InviteCode: "377385143",
},
}
}
+7 -4
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"honoka-chan/config"
"honoka-chan/encrypt"
"honoka-chan/model"
"honoka-chan/tools"
@@ -975,18 +976,20 @@ func Api(ctx *gin.Context) {
Cols("unit_removable_skill_id").Find(&removeSkillIds)
CheckErr(err)
userId, err := strconv.Atoi(config.Conf.UserPrefs.InviteCode)
CheckErr(err)
profileResp := model.ProfileResp{
Result: model.ProfileRes{
UserInfo: model.ProfileUserInfo{
UserID: pref.UserID,
UserID: userId,
Name: pref.UserName,
Level: pref.UserLevel,
Level: config.Conf.UserPrefs.Level,
CostMax: 100,
UnitMax: 5000,
EnergyMax: 1000,
EnergyMax: config.Conf.UserPrefs.EnergyMax,
FriendMax: 99,
UnitCnt: int(commonUnit + userUnit),
InviteCode: strconv.Itoa(pref.UserID),
InviteCode: config.Conf.UserPrefs.InviteCode,
ElapsedTimeFromLogin: "14\u5c0f\u65f6\u524d",
Introduction: pref.UserDesc,
},
+20 -10
View File
@@ -4,8 +4,10 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/encrypt"
"honoka-chan/model"
"honoka-chan/tools"
"net/http"
"strconv"
"time"
@@ -17,31 +19,39 @@ func UserInfo(ctx *gin.Context) {
userId, err := strconv.Atoi(ctx.GetString("userid"))
CheckErr(err)
pref := tools.UserPref{}
exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", userId).Get(&pref)
CheckErr(err)
if !exists {
ctx.String(http.StatusForbidden, ErrorMsg)
return
}
userResp := model.UserInfoResp{
ResponseData: model.UserInfoRes{
User: model.UserInfo{
UserID: userId,
Name: "\u68a6\u8def @\u65c5\u7acb\u3061\u306e\u65e5\u306b",
Level: 1028,
Exp: 28824396,
PreviousExp: 27734700,
NextExp: 28941885,
GameCoin: 112124104,
SnsCoin: 0,
Name: pref.UserName,
Level: config.Conf.UserPrefs.Level,
Exp: config.Conf.UserPrefs.ExpNumerator,
PreviousExp: 0,
NextExp: config.Conf.UserPrefs.ExpDenominator,
GameCoin: config.Conf.UserPrefs.GameCoin,
SnsCoin: config.Conf.UserPrefs.SnsCoin,
FreeSnsCoin: 0,
PaidSnsCoin: 0,
SocialPoint: 1438395,
UnitMax: 5000,
WaitingUnitMax: 1000,
EnergyMax: 417,
EnergyMax: config.Conf.UserPrefs.EnergyMax,
EnergyFullTime: "2023-03-20 03:58:55",
LicenseLiveEnergyRecoverlyTime: 60,
EnergyFullNeedTime: 0,
OverMaxEnergy: 0,
OverMaxEnergy: config.Conf.UserPrefs.OverMaxEnergy,
TrainingEnergy: 100,
TrainingEnergyMax: 100,
FriendMax: 99,
InviteCode: "377385143",
InviteCode: config.Conf.UserPrefs.InviteCode,
InsertDate: "2015-08-10 18:58:30",
UpdateDate: "2018-08-09 18:13:12",
TutorialState: -1,