Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e77d94ca
authored
Aug 14, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: log page 'Cannot read properties of undefined (reading 'length')'
parent
d22bc234
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
6 deletions
+16
-6
controller/log.go
+9
-4
model/log.go
+6
-2
web/src/components/LogsTable.js
+1
-0
No files found.
controller/log.go
View file @
e77d94ca
...
@@ -48,8 +48,8 @@ func GetAllLogs(c *gin.Context) {
...
@@ -48,8 +48,8 @@ func GetAllLogs(c *gin.Context) {
func
GetUserLogs
(
c
*
gin
.
Context
)
{
func
GetUserLogs
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
p
<
0
{
if
p
<
1
{
p
=
0
p
=
1
}
}
if
pageSize
<
0
{
if
pageSize
<
0
{
pageSize
=
common
.
ItemsPerPage
pageSize
=
common
.
ItemsPerPage
...
@@ -63,7 +63,7 @@ func GetUserLogs(c *gin.Context) {
...
@@ -63,7 +63,7 @@ func GetUserLogs(c *gin.Context) {
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
tokenName
:=
c
.
Query
(
"token_name"
)
tokenName
:=
c
.
Query
(
"token_name"
)
modelName
:=
c
.
Query
(
"model_name"
)
modelName
:=
c
.
Query
(
"model_name"
)
logs
,
err
:=
model
.
GetUserLogs
(
userId
,
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
tokenName
,
p
*
pageSize
,
pageSize
)
logs
,
total
,
err
:=
model
.
GetUserLogs
(
userId
,
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
tokenName
,
(
p
-
1
)
*
pageSize
,
pageSize
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
...
@@ -74,7 +74,12 @@ func GetUserLogs(c *gin.Context) {
...
@@ -74,7 +74,12 @@ func GetUserLogs(c *gin.Context) {
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"success"
:
true
,
"message"
:
""
,
"message"
:
""
,
"data"
:
logs
,
"data"
:
map
[
string
]
any
{
"items"
:
logs
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
})
return
return
}
}
...
...
model/log.go
View file @
e77d94ca
...
@@ -132,7 +132,7 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
...
@@ -132,7 +132,7 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
return
logs
,
total
,
err
return
logs
,
total
,
err
}
}
func
GetUserLogs
(
userId
int
,
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
tokenName
string
,
startIdx
int
,
num
int
)
(
logs
[]
*
Log
,
err
error
)
{
func
GetUserLogs
(
userId
int
,
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
tokenName
string
,
startIdx
int
,
num
int
)
(
logs
[]
*
Log
,
total
int64
,
err
error
)
{
var
tx
*
gorm
.
DB
var
tx
*
gorm
.
DB
if
logType
==
LogTypeUnknown
{
if
logType
==
LogTypeUnknown
{
tx
=
LOG_DB
.
Where
(
"user_id = ?"
,
userId
)
tx
=
LOG_DB
.
Where
(
"user_id = ?"
,
userId
)
...
@@ -151,6 +151,10 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
...
@@ -151,6 +151,10 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
if
endTimestamp
!=
0
{
if
endTimestamp
!=
0
{
tx
=
tx
.
Where
(
"created_at <= ?"
,
endTimestamp
)
tx
=
tx
.
Where
(
"created_at <= ?"
,
endTimestamp
)
}
}
err
=
tx
.
Model
(
&
Log
{})
.
Count
(
&
total
)
.
Error
if
err
!=
nil
{
return
nil
,
0
,
err
}
err
=
tx
.
Order
(
"id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Omit
(
"id"
)
.
Find
(
&
logs
)
.
Error
err
=
tx
.
Order
(
"id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Omit
(
"id"
)
.
Find
(
&
logs
)
.
Error
for
i
:=
range
logs
{
for
i
:=
range
logs
{
var
otherMap
map
[
string
]
interface
{}
var
otherMap
map
[
string
]
interface
{}
...
@@ -161,7 +165,7 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
...
@@ -161,7 +165,7 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
}
}
logs
[
i
]
.
Other
=
common
.
MapToJsonStr
(
otherMap
)
logs
[
i
]
.
Other
=
common
.
MapToJsonStr
(
otherMap
)
}
}
return
logs
,
err
return
logs
,
total
,
err
}
}
func
SearchAllLogs
(
keyword
string
)
(
logs
[]
*
Log
,
err
error
)
{
func
SearchAllLogs
(
keyword
string
)
(
logs
[]
*
Log
,
err
error
)
{
...
...
web/src/components/LogsTable.js
View file @
e77d94ca
...
@@ -534,6 +534,7 @@ const LogsTable = () => {
...
@@ -534,6 +534,7 @@ const LogsTable = () => {
const
res
=
await
API
.
get
(
url
);
const
res
=
await
API
.
get
(
url
);
const
{
success
,
message
,
data
}
=
res
.
data
;
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
if
(
success
)
{
console
.
log
(
data
);
const
newPageData
=
data
.
items
;
const
newPageData
=
data
.
items
;
setActivePage
(
data
.
page
);
setActivePage
(
data
.
page
);
setPageSize
(
data
.
page_size
);
setPageSize
(
data
.
page_size
);
...
...
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