mirror of
https://github.com/usememos/memos.git
synced 2025-10-25 05:46:03 +08:00
chore: fix linter
This commit is contained in:
parent
bbd984a754
commit
b8a37c7229
3 changed files with 10 additions and 9 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/usememos/memos/internal/util"
|
||||
)
|
||||
|
|
@ -79,12 +80,12 @@ func BuildSessionCookieValue(userID int32, sessionID string) string {
|
|||
func ParseSessionCookieValue(cookieValue string) (int32, string, error) {
|
||||
parts := strings.SplitN(cookieValue, "-", 2)
|
||||
if len(parts) != 2 {
|
||||
return 0, "", fmt.Errorf("invalid session cookie format")
|
||||
return 0, "", errors.New("invalid session cookie format")
|
||||
}
|
||||
|
||||
userID, err := util.ConvertStringToInt32(parts[0])
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("invalid user ID in session cookie: %v", err)
|
||||
return 0, "", errors.Errorf("invalid user ID in session cookie: %v", err)
|
||||
}
|
||||
|
||||
return userID, parts[1], nil
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ func (s *APIV1Service) trackUserSession(ctx context.Context, userID int32, sessi
|
|||
// - DeviceType: "mobile", "tablet", or "desktop"
|
||||
// - Os: Operating system name and version (e.g., "iOS 17.1", "Windows 10/11")
|
||||
// - Browser: Browser name and version (e.g., "Chrome 120.0.0.0")
|
||||
// - Country: Geographic location (TODO: implement with GeoIP service)
|
||||
// - Country: Geographic location (TODO: implement with GeoIP service).
|
||||
func (s *APIV1Service) extractClientInfo(ctx context.Context) *storepb.SessionsUserSetting_ClientInfo {
|
||||
clientInfo := &storepb.SessionsUserSetting_ClientInfo{}
|
||||
|
||||
|
|
@ -412,8 +412,8 @@ func (s *APIV1Service) extractClientInfo(ctx context.Context) *storepb.SessionsU
|
|||
return clientInfo
|
||||
}
|
||||
|
||||
// parseUserAgent extracts device type, OS, and browser information from user agent string
|
||||
func (s *APIV1Service) parseUserAgent(userAgent string, clientInfo *storepb.SessionsUserSetting_ClientInfo) {
|
||||
// parseUserAgent extracts device type, OS, and browser information from user agent string.
|
||||
func (*APIV1Service) parseUserAgent(userAgent string, clientInfo *storepb.SessionsUserSetting_ClientInfo) {
|
||||
if userAgent == "" {
|
||||
return
|
||||
}
|
||||
|
|
@ -440,7 +440,7 @@ func (s *APIV1Service) parseUserAgent(userAgent string, clientInfo *storepb.Sess
|
|||
versionStart := idx + 7
|
||||
versionEnd := strings.Index(userAgent[versionStart:], " ")
|
||||
if versionEnd != -1 {
|
||||
version := strings.Replace(userAgent[versionStart:versionStart+versionEnd], "_", ".", -1)
|
||||
version := strings.ReplaceAll(userAgent[versionStart:versionStart+versionEnd], "_", ".")
|
||||
clientInfo.Os = "iOS " + version
|
||||
} else {
|
||||
clientInfo.Os = "iOS"
|
||||
|
|
@ -449,7 +449,7 @@ func (s *APIV1Service) parseUserAgent(userAgent string, clientInfo *storepb.Sess
|
|||
versionStart := idx + 10
|
||||
versionEnd := strings.Index(userAgent[versionStart:], " ")
|
||||
if versionEnd != -1 {
|
||||
version := strings.Replace(userAgent[versionStart:versionStart+versionEnd], "_", ".", -1)
|
||||
version := strings.ReplaceAll(userAgent[versionStart:versionStart+versionEnd], "_", ".")
|
||||
clientInfo.Os = "iOS " + version
|
||||
} else {
|
||||
clientInfo.Os = "iOS"
|
||||
|
|
@ -491,7 +491,7 @@ func (s *APIV1Service) parseUserAgent(userAgent string, clientInfo *storepb.Sess
|
|||
versionEnd = strings.Index(userAgent[versionStart:], ")")
|
||||
}
|
||||
if versionEnd != -1 {
|
||||
version := strings.Replace(userAgent[versionStart:versionStart+versionEnd], "_", ".", -1)
|
||||
version := strings.ReplaceAll(userAgent[versionStart:versionStart+versionEnd], "_", ".")
|
||||
clientInfo.Os = "macOS " + version
|
||||
} else {
|
||||
clientInfo.Os = "macOS"
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ func TestExtractClientInfo(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestClientInfoExamples demonstrates the enhanced client info extraction with various user agents
|
||||
// TestClientInfoExamples demonstrates the enhanced client info extraction with various user agents.
|
||||
func TestClientInfoExamples(t *testing.T) {
|
||||
service := &APIV1Service{}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue