mirror of
https://github.com/linux-do/new-api.git
synced 2025-10-17 21:03:41 +08:00
chore: format logs
This commit is contained in:
@@ -137,13 +137,13 @@ func InitChannelCache() {
|
||||
channelSyncLock.Lock()
|
||||
group2model2channels = newGroup2model2channels
|
||||
channelSyncLock.Unlock()
|
||||
common.SysLog("Channels synced from database")
|
||||
common.SysLog("channels synced from database")
|
||||
}
|
||||
|
||||
func SyncChannelCache(frequency int) {
|
||||
for {
|
||||
time.Sleep(time.Duration(frequency) * time.Second)
|
||||
common.SysLog("Syncing channels from database")
|
||||
common.SysLog("syncing channels from database")
|
||||
InitChannelCache()
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ func InitDB() (err error) {
|
||||
PrepareStmt: true, // precompile SQL
|
||||
})
|
||||
}
|
||||
common.SysLog("Database connected")
|
||||
common.SysLog("database connected")
|
||||
if err == nil {
|
||||
DB = db
|
||||
if !common.IsMasterNode {
|
||||
@@ -88,7 +88,7 @@ func InitDB() (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
common.SysLog("Database migrated")
|
||||
common.SysLog("database migrated")
|
||||
err = createRootAccountIfNeed()
|
||||
return err
|
||||
} else {
|
||||
|
@@ -75,7 +75,7 @@ func loadOptionsFromDatabase() {
|
||||
for _, option := range options {
|
||||
err := updateOptionMap(option.Key, option.Value)
|
||||
if err != nil {
|
||||
common.SysError("Failed to update option map: " + err.Error())
|
||||
common.SysError("failed to update option map: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func loadOptionsFromDatabase() {
|
||||
func SyncOptions(frequency int) {
|
||||
for {
|
||||
time.Sleep(time.Duration(frequency) * time.Second)
|
||||
common.SysLog("Syncing options from database")
|
||||
common.SysLog("syncing options from database")
|
||||
loadOptionsFromDatabase()
|
||||
}
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ func Redeem(key string, userId int) (quota int, err error) {
|
||||
redemption.Status = common.RedemptionCodeStatusUsed
|
||||
err := redemption.SelectUpdate()
|
||||
if err != nil {
|
||||
common.SysError("更新兑换码状态失败:" + err.Error())
|
||||
common.SysError("failed to update redemption status: " + err.Error())
|
||||
}
|
||||
RecordLog(userId, LogTypeTopup, fmt.Sprintf("通过兑换码充值 %s", common.LogQuota(redemption.Quota)))
|
||||
}()
|
||||
|
@@ -45,7 +45,7 @@ func ValidateUserToken(key string) (token *Token, err error) {
|
||||
token.Status = common.TokenStatusExpired
|
||||
err := token.SelectUpdate()
|
||||
if err != nil {
|
||||
common.SysError("更新令牌状态失败:" + err.Error())
|
||||
common.SysError("failed to update token status" + err.Error())
|
||||
}
|
||||
return nil, errors.New("该令牌已过期")
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func ValidateUserToken(key string) (token *Token, err error) {
|
||||
token.Status = common.TokenStatusExhausted
|
||||
err := token.SelectUpdate()
|
||||
if err != nil {
|
||||
common.SysError("更新令牌状态失败:" + err.Error())
|
||||
common.SysError("failed to update token status" + err.Error())
|
||||
}
|
||||
return nil, errors.New("该令牌额度已用尽")
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func ValidateUserToken(key string) (token *Token, err error) {
|
||||
token.AccessedTime = common.GetTimestamp()
|
||||
err := token.SelectUpdate()
|
||||
if err != nil {
|
||||
common.SysError("更新令牌失败:" + err.Error())
|
||||
common.SysError("failed to update token" + err.Error())
|
||||
}
|
||||
}()
|
||||
return token, nil
|
||||
@@ -166,7 +166,7 @@ func PreConsumeTokenQuota(tokenId int, quota int) (err error) {
|
||||
go func() {
|
||||
email, err := GetUserEmail(token.UserId)
|
||||
if err != nil {
|
||||
common.SysError("获取用户邮箱失败:" + err.Error())
|
||||
common.SysError("failed to fetch user email: " + err.Error())
|
||||
}
|
||||
prompt := "您的额度即将用尽"
|
||||
if noMoreQuota {
|
||||
@@ -177,7 +177,7 @@ func PreConsumeTokenQuota(tokenId int, quota int) (err error) {
|
||||
err = common.SendEmail(prompt, email,
|
||||
fmt.Sprintf("%s,当前剩余额度为 %d,为了不影响您的使用,请及时充值。<br/>充值链接:<a href='%s'>%s</a>", prompt, userQuota, topUpLink, topUpLink))
|
||||
if err != nil {
|
||||
common.SysError("发送邮件失败:" + err.Error())
|
||||
common.SysError("failed to send email" + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@@ -220,7 +220,7 @@ func IsAdmin(userId int) bool {
|
||||
var user User
|
||||
err := DB.Where("id = ?", userId).Select("role").Find(&user).Error
|
||||
if err != nil {
|
||||
common.SysError("No such user " + err.Error())
|
||||
common.SysError("no such user " + err.Error())
|
||||
return false
|
||||
}
|
||||
return user.Role >= common.RoleAdminUser
|
||||
@@ -233,7 +233,7 @@ func IsUserEnabled(userId int) bool {
|
||||
var user User
|
||||
err := DB.Where("id = ?", userId).Select("status").Find(&user).Error
|
||||
if err != nil {
|
||||
common.SysError("No such user " + err.Error())
|
||||
common.SysError("no such user " + err.Error())
|
||||
return false
|
||||
}
|
||||
return user.Status == common.UserStatusEnabled
|
||||
@@ -300,6 +300,6 @@ func UpdateUserUsedQuotaAndRequestCount(id int, quota int) {
|
||||
},
|
||||
).Error
|
||||
if err != nil {
|
||||
common.SysError("Failed to update user used quota and request count: " + err.Error())
|
||||
common.SysError("failed to update user used quota and request count: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user