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
9006d921
authored
Nov 19, 2024
by
Calcium-Ion
Committed by
GitHub
Nov 19, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #493 from xixingya/feature/bug-fix
ratio must gte 0
parents
4496cb53
a6de89aa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
1 deletions
+32
-1
common/group-ratio.go
+15
-0
controller/option.go
+9
-0
web/src/pages/Setting/Operation/SettingsMagnification.js
+8
-1
No files found.
common/group-ratio.go
View file @
9006d921
...
@@ -2,6 +2,7 @@ package common
...
@@ -2,6 +2,7 @@ package common
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
)
)
var
GroupRatio
=
map
[
string
]
float64
{
var
GroupRatio
=
map
[
string
]
float64
{
...
@@ -31,3 +32,17 @@ func GetGroupRatio(name string) float64 {
...
@@ -31,3 +32,17 @@ func GetGroupRatio(name string) float64 {
}
}
return
ratio
return
ratio
}
}
func
CheckGroupRatio
(
jsonStr
string
)
error
{
checkGroupRatio
:=
make
(
map
[
string
]
float64
)
err
:=
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
checkGroupRatio
)
if
err
!=
nil
{
return
err
}
for
name
,
ratio
:=
range
checkGroupRatio
{
if
ratio
<
0
{
return
errors
.
New
(
"group ratio must be not less than 0: "
+
name
)
}
}
return
nil
}
controller/option.go
View file @
9006d921
...
@@ -82,6 +82,15 @@ func UpdateOption(c *gin.Context) {
...
@@ -82,6 +82,15 @@ func UpdateOption(c *gin.Context) {
})
})
return
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
)
err
=
model
.
UpdateOption
(
option
.
Key
,
option
.
Value
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
web/src/pages/Setting/Operation/SettingsMagnification.js
View file @
9006d921
...
@@ -50,10 +50,17 @@ export default function SettingsMagnification(props) {
...
@@ -50,10 +50,17 @@ export default function SettingsMagnification(props) {
if
(
res
.
includes
(
undefined
))
if
(
res
.
includes
(
undefined
))
return
showError
(
'部分保存失败,请重试'
);
return
showError
(
'部分保存失败,请重试'
);
}
}
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
if
(
!
res
[
i
].
data
.
success
)
{
return
showError
(
res
[
i
].
data
.
message
)
}
}
showSuccess
(
'保存成功'
);
showSuccess
(
'保存成功'
);
props
.
refresh
();
props
.
refresh
();
})
})
.
catch
(()
=>
{
.
catch
(
error
=>
{
console
.
error
(
'Unexpected error in Promise.all:'
,
error
);
showError
(
'保存失败,请重试'
);
showError
(
'保存失败,请重试'
);
})
})
.
finally
(()
=>
{
.
finally
(()
=>
{
...
...
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