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
05db6660
authored
Sep 20, 2024
by
liuzhifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ratio must gte 0
parent
9e8faac4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
9 deletions
+22
-9
common/group-ratio.go
+8
-9
controller/option.go
+9
-0
web/src/pages/Setting/Operation/SettingsMagnification.js
+5
-0
No files found.
common/group-ratio.go
View file @
05db6660
...
...
@@ -20,14 +20,8 @@ func GroupRatio2JSONString() string {
}
func
UpdateGroupRatioByJSONString
(
jsonStr
string
)
error
{
tempGroupRatio
:=
make
(
map
[
string
]
float64
)
err
:=
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
tempGroupRatio
)
err
=
checkGroupRatio
(
tempGroupRatio
)
if
err
!=
nil
{
return
err
}
GroupRatio
=
tempGroupRatio
return
err
GroupRatio
=
make
(
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
GroupRatio
)
}
func
GetGroupRatio
(
name
string
)
float64
{
...
...
@@ -39,7 +33,12 @@ func GetGroupRatio(name string) float64 {
return
ratio
}
func
checkGroupRatio
(
checkGroupRatio
map
[
string
]
float64
)
error
{
func
CheckGroupRatio
(
jsonStr
string
)
error
{
checkGroupRatio
:=
make
(
map
[
string
]
float64
)
err
:=
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
GroupRatio
)
if
err
!=
nil
{
return
err
}
for
name
,
ratio
:=
range
checkGroupRatio
{
if
ratio
<
0
{
return
errors
.
New
(
"group ratio must be greater than 0: "
+
name
)
...
...
controller/option.go
View file @
05db6660
...
...
@@ -74,6 +74,15 @@ func UpdateOption(c *gin.Context) {
})
return
}
case
"GroupRatio"
:
err
=
common
.
CheckGroupRatio
(
option
.
Value
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
}
}
err
=
model
.
UpdateOption
(
option
.
Key
,
option
.
Value
)
if
err
!=
nil
{
...
...
web/src/pages/Setting/Operation/SettingsMagnification.js
View file @
05db6660
...
...
@@ -50,6 +50,11 @@ export default function SettingsMagnification(props) {
if
(
res
.
includes
(
undefined
))
return
showError
(
'部分保存失败,请重试'
);
}
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
if
(
!
res
[
i
].
success
)
{
return
showError
(
res
[
i
].
message
)
}
}
showSuccess
(
'保存成功'
);
props
.
refresh
();
})
...
...
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