mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
refactor: Update PeerInfo to extract and store comprehensive device information
This commit is contained in:
parent
fb9f41248f
commit
d9f2b21812
@ -48,11 +48,15 @@ func (s *HTTPContext) InitSession() error {
|
||||
result := s.db.Where("id = ?", sessionID).First(&sess)
|
||||
if result.Error != nil {
|
||||
// Create new session if not found
|
||||
bn, bv := extractBrowserInfo(s.Context)
|
||||
bn, bv, arch, plat, platVer, model := extractBrowserInfo(s.Context)
|
||||
sess = database.Session{
|
||||
ID: sessionID,
|
||||
BrowserName: bn,
|
||||
BrowserVersion: bv,
|
||||
UserArchitecture: arch,
|
||||
Platform: plat,
|
||||
PlatformVersion: platVer,
|
||||
DeviceModel: model,
|
||||
}
|
||||
if err := s.db.Create(&sess).Error; err != nil {
|
||||
return err
|
||||
|
@ -22,30 +22,51 @@ func Middleware(db *gorm.DB) echo.MiddlewareFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func extractBrowserInfo(c echo.Context) (string, string) {
|
||||
userAgent := common.HeaderRead(c, common.UserAgent)
|
||||
if userAgent == "" {
|
||||
return "N/A", "-1"
|
||||
func extractBrowserInfo(c echo.Context) (string, string, string, string, string, string) {
|
||||
// Extract all relevant headers
|
||||
browserName := common.HeaderRead(c, common.UserAgent)
|
||||
arch := common.HeaderRead(c, common.Architecture)
|
||||
platform := common.HeaderRead(c, common.Platform)
|
||||
platformVer := common.HeaderRead(c, common.PlatformVersion)
|
||||
model := common.HeaderRead(c, common.Model)
|
||||
fullVersionList := common.HeaderRead(c, common.FullVersionList)
|
||||
|
||||
// Default values if headers are empty
|
||||
if browserName == "" {
|
||||
browserName = "N/A"
|
||||
}
|
||||
if arch == "" {
|
||||
arch = "unknown"
|
||||
}
|
||||
if platform == "" {
|
||||
platform = "unknown"
|
||||
}
|
||||
if platformVer == "" {
|
||||
platformVer = "unknown"
|
||||
}
|
||||
if model == "" {
|
||||
model = "unknown"
|
||||
}
|
||||
|
||||
var name, ver string
|
||||
entries := strings.Split(strings.TrimSpace(userAgent), ",")
|
||||
// Extract browser version from full version list
|
||||
version := "-1"
|
||||
if fullVersionList != "" {
|
||||
entries := strings.Split(strings.TrimSpace(fullVersionList), ",")
|
||||
for _, entry := range entries {
|
||||
entry = strings.TrimSpace(entry)
|
||||
re := regexp.MustCompile(`"([^"]+)";v="([^"]+)"`)
|
||||
matches := re.FindStringSubmatch(entry)
|
||||
|
||||
if len(matches) == 3 {
|
||||
browserName := matches[1]
|
||||
version := matches[2]
|
||||
|
||||
if browserName != common.BrowserNameUnknown.String() &&
|
||||
browserName != common.BrowserNameChromium.String() {
|
||||
name = browserName
|
||||
ver = version
|
||||
browserName = matches[1]
|
||||
version = matches[2]
|
||||
if browserName != "Not.A/Brand" &&
|
||||
browserName != "Chromium" {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return name, ver
|
||||
}
|
||||
|
||||
return browserName, version, arch, platform, platformVer, model
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user