mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
refactor: migrate UI components to nebula module
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/onsonr/sonr/pkg/common"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -17,3 +21,31 @@ 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"
|
||||
}
|
||||
|
||||
var name, ver string
|
||||
entries := strings.Split(strings.TrimSpace(userAgent), ",")
|
||||
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
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return name, ver
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user