refactor: migrate UI components to nebula module

This commit is contained in:
Prad Nukala
2024-12-08 16:17:21 -05:00
parent c64c506c52
commit b65e844824
34 changed files with 62 additions and 2291 deletions
+7 -37
View File
@@ -2,8 +2,6 @@ package session
import (
"net/http"
"regexp"
"strings"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/common"
@@ -12,6 +10,13 @@ import (
"gorm.io/gorm"
)
// HTTPContext is the context for HTTP endpoints.
type HTTPContext struct {
echo.Context
db *gorm.DB
sess *database.Session
}
// Get returns the HTTPContext from the echo context
func Get(c echo.Context) (*HTTPContext, error) {
ctx, ok := c.(*HTTPContext)
@@ -21,13 +26,6 @@ func Get(c echo.Context) (*HTTPContext, error) {
return ctx, nil
}
// HTTPContext is the context for HTTP endpoints.
type HTTPContext struct {
echo.Context
db *gorm.DB
sess *database.Session
}
// NewHTTPContext creates a new session context
func NewHTTPContext(c echo.Context, db *gorm.DB) *HTTPContext {
return &HTTPContext{
@@ -79,31 +77,3 @@ func (s *HTTPContext) getOrCreateSessionID() string {
}
return sessionID
}
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
}
@@ -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
}