mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +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)
|
result := s.db.Where("id = ?", sessionID).First(&sess)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
// Create new session if not found
|
// Create new session if not found
|
||||||
bn, bv := extractBrowserInfo(s.Context)
|
bn, bv, arch, plat, platVer, model := extractBrowserInfo(s.Context)
|
||||||
sess = database.Session{
|
sess = database.Session{
|
||||||
ID: sessionID,
|
ID: sessionID,
|
||||||
BrowserName: bn,
|
BrowserName: bn,
|
||||||
BrowserVersion: bv,
|
BrowserVersion: bv,
|
||||||
|
UserArchitecture: arch,
|
||||||
|
Platform: plat,
|
||||||
|
PlatformVersion: platVer,
|
||||||
|
DeviceModel: model,
|
||||||
}
|
}
|
||||||
if err := s.db.Create(&sess).Error; err != nil {
|
if err := s.db.Create(&sess).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -22,30 +22,51 @@ func Middleware(db *gorm.DB) echo.MiddlewareFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractBrowserInfo(c echo.Context) (string, string) {
|
func extractBrowserInfo(c echo.Context) (string, string, string, string, string, string) {
|
||||||
userAgent := common.HeaderRead(c, common.UserAgent)
|
// Extract all relevant headers
|
||||||
if userAgent == "" {
|
browserName := common.HeaderRead(c, common.UserAgent)
|
||||||
return "N/A", "-1"
|
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
|
// Extract browser version from full version list
|
||||||
entries := strings.Split(strings.TrimSpace(userAgent), ",")
|
version := "-1"
|
||||||
|
if fullVersionList != "" {
|
||||||
|
entries := strings.Split(strings.TrimSpace(fullVersionList), ",")
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
entry = strings.TrimSpace(entry)
|
entry = strings.TrimSpace(entry)
|
||||||
re := regexp.MustCompile(`"([^"]+)";v="([^"]+)"`)
|
re := regexp.MustCompile(`"([^"]+)";v="([^"]+)"`)
|
||||||
matches := re.FindStringSubmatch(entry)
|
matches := re.FindStringSubmatch(entry)
|
||||||
|
|
||||||
if len(matches) == 3 {
|
if len(matches) == 3 {
|
||||||
browserName := matches[1]
|
browserName = matches[1]
|
||||||
version := matches[2]
|
version = matches[2]
|
||||||
|
if browserName != "Not.A/Brand" &&
|
||||||
if browserName != common.BrowserNameUnknown.String() &&
|
browserName != "Chromium" {
|
||||||
browserName != common.BrowserNameChromium.String() {
|
|
||||||
name = browserName
|
|
||||||
ver = version
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return name, ver
|
}
|
||||||
|
|
||||||
|
return browserName, version, arch, platform, platformVer, model
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user