Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
b8a37c72
Commit
b8a37c72
authored
Jun 23, 2025
by
Johnny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix linter
parent
bbd984a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
9 deletions
+10
-9
auth.go
server/router/api/v1/auth.go
+3
-2
auth_service.go
server/router/api/v1/auth_service.go
+6
-6
auth_service_client_info_test.go
server/router/api/v1/auth_service_client_info_test.go
+1
-1
No files found.
server/router/api/v1/auth.go
View file @
b8a37c72
...
...
@@ -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
...
...
server/router/api/v1/auth_service.go
View file @
b8a37c72
...
...
@@ -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
.
Replace
All
(
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
.
Replace
All
(
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
.
Replace
All
(
userAgent
[
versionStart
:
versionStart
+
versionEnd
],
"_"
,
"."
)
clientInfo
.
Os
=
"macOS "
+
version
}
else
{
clientInfo
.
Os
=
"macOS"
...
...
server/router/api/v1/auth_service_client_info_test.go
View file @
b8a37c72
...
...
@@ -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
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment