mirror of https://github.com/bjdgyc/anylink.git
Merge pull request #201 from lanrenwo/useractlog_limitchar
修复PlatformVersion字段溢出的问题
This commit is contained in:
commit
9809b407d5
|
@ -50,7 +50,7 @@ type UserActLog struct {
|
|||
Client uint8 `json:"client" xorm:"not null default 0 Int"`
|
||||
Version string `json:"version" xorm:"varchar(15)"`
|
||||
DeviceType string `json:"device_type" xorm:"varchar(128) not null default ''"`
|
||||
PlatformVersion string `json:"platform_version" xorm:"varchar(15) not null default ''"`
|
||||
PlatformVersion string `json:"platform_version" xorm:"varchar(128) not null default ''"`
|
||||
Status uint8 `json:"status" xorm:"not null default 0 Int"`
|
||||
Info string `json:"info" xorm:"varchar(255) not null default ''"` // 详情
|
||||
CreatedAt time.Time `json:"created_at" xorm:"DateTime created"`
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/bjdgyc/anylink/base"
|
||||
"github.com/ivpusic/grpool"
|
||||
"github.com/spf13/cast"
|
||||
"xorm.io/xorm"
|
||||
|
@ -85,8 +86,17 @@ func (ua *UserActLogProcess) Add(u UserActLog, userAgent string) {
|
|||
u.Info = u.Info[2:]
|
||||
}
|
||||
}
|
||||
// limit the max length of char
|
||||
u.Version = substr(u.Version, 0, 15)
|
||||
u.DeviceType = substr(u.DeviceType, 0, 128)
|
||||
u.PlatformVersion = substr(u.PlatformVersion, 0, 128)
|
||||
u.Info = substr(u.Info, 0, 255)
|
||||
|
||||
UserActLogIns.Pool.JobQueue <- func() {
|
||||
_ = Add(u)
|
||||
err := Add(u)
|
||||
if err != nil {
|
||||
base.Error("Add UserActLog error: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,6 +127,7 @@ func (ua *UserActLogProcess) GetInfoOpsById(id uint8) string {
|
|||
return ua.InfoOps[id]
|
||||
}
|
||||
|
||||
// 解析user agent
|
||||
func (ua *UserActLogProcess) ParseUserAgent(userAgent string) (os_idx, client_idx uint8, ver string) {
|
||||
// Unknown
|
||||
if len(userAgent) == 0 {
|
||||
|
@ -187,3 +198,13 @@ func (ua *UserActLogProcess) GetSession(values url.Values) *xorm.Session {
|
|||
}
|
||||
return session
|
||||
}
|
||||
|
||||
// 截取字符串
|
||||
func substr(s string, pos, length int) string {
|
||||
runes := []rune(s)
|
||||
l := pos + length
|
||||
if l > len(runes) {
|
||||
l = len(runes)
|
||||
}
|
||||
return string(runes[pos:l])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue