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
fa2d80c6
authored
May 16, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fix option update logic not working properly
parent
ca3ab405
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
9 deletions
+25
-9
common/constants.go
+1
-1
model/option.go
+3
-0
web/src/components/OtherSetting.js
+2
-4
web/src/components/SystemSetting.js
+19
-4
No files found.
common/constants.go
View file @
fa2d80c6
...
@@ -51,9 +51,9 @@ var TurnstileSiteKey = ""
...
@@ -51,9 +51,9 @@ var TurnstileSiteKey = ""
var
TurnstileSecretKey
=
""
var
TurnstileSecretKey
=
""
var
QuotaForNewUser
=
100
var
QuotaForNewUser
=
100
var
ChannelDisableThreshold
=
5.0
var
ChannelDisableThreshold
=
5.0
var
AutomaticDisableChannelEnabled
=
false
var
AutomaticDisableChannelEnabled
=
false
var
QuotaRemindThreshold
=
1000
// TODO: QuotaRemindThreshold
var
RootUserEmail
=
""
var
RootUserEmail
=
""
...
...
model/option.go
View file @
fa2d80c6
...
@@ -54,6 +54,7 @@ func InitOptionMap() {
...
@@ -54,6 +54,7 @@ func InitOptionMap() {
common
.
OptionMap
[
"TurnstileSiteKey"
]
=
""
common
.
OptionMap
[
"TurnstileSiteKey"
]
=
""
common
.
OptionMap
[
"TurnstileSecretKey"
]
=
""
common
.
OptionMap
[
"TurnstileSecretKey"
]
=
""
common
.
OptionMap
[
"QuotaForNewUser"
]
=
strconv
.
Itoa
(
common
.
QuotaForNewUser
)
common
.
OptionMap
[
"QuotaForNewUser"
]
=
strconv
.
Itoa
(
common
.
QuotaForNewUser
)
common
.
OptionMap
[
"QuotaRemindThreshold"
]
=
strconv
.
Itoa
(
common
.
QuotaRemindThreshold
)
common
.
OptionMap
[
"ModelRatio"
]
=
common
.
ModelRatio2JSONString
()
common
.
OptionMap
[
"ModelRatio"
]
=
common
.
ModelRatio2JSONString
()
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMapRWMutex
.
Unlock
()
common
.
OptionMapRWMutex
.
Unlock
()
...
@@ -156,6 +157,8 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -156,6 +157,8 @@ func updateOptionMap(key string, value string) (err error) {
common
.
TurnstileSecretKey
=
value
common
.
TurnstileSecretKey
=
value
case
"QuotaForNewUser"
:
case
"QuotaForNewUser"
:
common
.
QuotaForNewUser
,
_
=
strconv
.
Atoi
(
value
)
common
.
QuotaForNewUser
,
_
=
strconv
.
Atoi
(
value
)
case
"QuotaRemindThreshold"
:
common
.
QuotaRemindThreshold
,
_
=
strconv
.
Atoi
(
value
)
case
"ModelRatio"
:
case
"ModelRatio"
:
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
case
"TopUpLink"
:
case
"TopUpLink"
:
...
...
web/src/components/OtherSetting.js
View file @
fa2d80c6
...
@@ -12,7 +12,6 @@ const OtherSetting = () => {
...
@@ -12,7 +12,6 @@ const OtherSetting = () => {
Logo
:
''
,
Logo
:
''
,
HomePageContent
:
''
,
HomePageContent
:
''
,
});
});
let
originInputs
=
{};
let
[
loading
,
setLoading
]
=
useState
(
false
);
let
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
showUpdateModal
,
setShowUpdateModal
]
=
useState
(
false
);
const
[
showUpdateModal
,
setShowUpdateModal
]
=
useState
(
false
);
const
[
updateData
,
setUpdateData
]
=
useState
({
const
[
updateData
,
setUpdateData
]
=
useState
({
...
@@ -21,7 +20,7 @@ const OtherSetting = () => {
...
@@ -21,7 +20,7 @@ const OtherSetting = () => {
});
});
const
getOptions
=
async
()
=>
{
const
getOptions
=
async
()
=>
{
const
res
=
await
API
.
get
(
'/api/option'
);
const
res
=
await
API
.
get
(
'/api/option
/
'
);
const
{
success
,
message
,
data
}
=
res
.
data
;
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
if
(
success
)
{
let
newInputs
=
{};
let
newInputs
=
{};
...
@@ -31,7 +30,6 @@ const OtherSetting = () => {
...
@@ -31,7 +30,6 @@ const OtherSetting = () => {
}
}
});
});
setInputs
(
newInputs
);
setInputs
(
newInputs
);
originInputs
=
newInputs
;
}
else
{
}
else
{
showError
(
message
);
showError
(
message
);
}
}
...
@@ -43,7 +41,7 @@ const OtherSetting = () => {
...
@@ -43,7 +41,7 @@ const OtherSetting = () => {
const
updateOption
=
async
(
key
,
value
)
=>
{
const
updateOption
=
async
(
key
,
value
)
=>
{
setLoading
(
true
);
setLoading
(
true
);
const
res
=
await
API
.
put
(
'/api/option'
,
{
const
res
=
await
API
.
put
(
'/api/option
/
'
,
{
key
,
key
,
value
,
value
,
});
});
...
...
web/src/components/SystemSetting.js
View file @
fa2d80c6
...
@@ -27,16 +27,17 @@ const SystemSetting = () => {
...
@@ -27,16 +27,17 @@ const SystemSetting = () => {
TurnstileSecretKey
:
''
,
TurnstileSecretKey
:
''
,
RegisterEnabled
:
''
,
RegisterEnabled
:
''
,
QuotaForNewUser
:
0
,
QuotaForNewUser
:
0
,
QuotaRemindThreshold
:
0
,
ModelRatio
:
''
,
ModelRatio
:
''
,
TopUpLink
:
''
,
TopUpLink
:
''
,
AutomaticDisableChannelEnabled
:
''
,
AutomaticDisableChannelEnabled
:
''
,
ChannelDisableThreshold
:
0
,
ChannelDisableThreshold
:
0
,
});
});
let
originInputs
=
{}
;
const
[
originInputs
,
setOriginInputs
]
=
useState
({})
;
let
[
loading
,
setLoading
]
=
useState
(
false
);
let
[
loading
,
setLoading
]
=
useState
(
false
);
const
getOptions
=
async
()
=>
{
const
getOptions
=
async
()
=>
{
const
res
=
await
API
.
get
(
'/api/option'
);
const
res
=
await
API
.
get
(
'/api/option
/
'
);
const
{
success
,
message
,
data
}
=
res
.
data
;
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
if
(
success
)
{
let
newInputs
=
{};
let
newInputs
=
{};
...
@@ -44,7 +45,7 @@ const SystemSetting = () => {
...
@@ -44,7 +45,7 @@ const SystemSetting = () => {
newInputs
[
item
.
key
]
=
item
.
value
;
newInputs
[
item
.
key
]
=
item
.
value
;
});
});
setInputs
(
newInputs
);
setInputs
(
newInputs
);
originInputs
=
newInputs
;
setOriginInputs
(
newInputs
)
;
}
else
{
}
else
{
showError
(
message
);
showError
(
message
);
}
}
...
@@ -70,7 +71,7 @@ const SystemSetting = () => {
...
@@ -70,7 +71,7 @@ const SystemSetting = () => {
default
:
default
:
break
;
break
;
}
}
const
res
=
await
API
.
put
(
'/api/option'
,
{
const
res
=
await
API
.
put
(
'/api/option
/
'
,
{
key
,
key
,
value
value
});
});
...
@@ -96,6 +97,7 @@ const SystemSetting = () => {
...
@@ -96,6 +97,7 @@ const SystemSetting = () => {
name
===
'TurnstileSiteKey'
||
name
===
'TurnstileSiteKey'
||
name
===
'TurnstileSecretKey'
||
name
===
'TurnstileSecretKey'
||
name
===
'QuotaForNewUser'
||
name
===
'QuotaForNewUser'
||
name
===
'QuotaRemindThreshold'
||
name
===
'ModelRatio'
||
name
===
'ModelRatio'
||
name
===
'TopUpLink'
name
===
'TopUpLink'
)
{
)
{
...
@@ -114,6 +116,9 @@ const SystemSetting = () => {
...
@@ -114,6 +116,9 @@ const SystemSetting = () => {
if
(
originInputs
[
'QuotaForNewUser'
]
!==
inputs
.
QuotaForNewUser
)
{
if
(
originInputs
[
'QuotaForNewUser'
]
!==
inputs
.
QuotaForNewUser
)
{
await
updateOption
(
'QuotaForNewUser'
,
inputs
.
QuotaForNewUser
);
await
updateOption
(
'QuotaForNewUser'
,
inputs
.
QuotaForNewUser
);
}
}
if
(
originInputs
[
'QuotaRemindThreshold'
]
!==
inputs
.
QuotaRemindThreshold
)
{
await
updateOption
(
'QuotaRemindThreshold'
,
inputs
.
QuotaRemindThreshold
);
}
if
(
originInputs
[
'ModelRatio'
]
!==
inputs
.
ModelRatio
)
{
if
(
originInputs
[
'ModelRatio'
]
!==
inputs
.
ModelRatio
)
{
if
(
!
verifyJSON
(
inputs
.
ModelRatio
))
{
if
(
!
verifyJSON
(
inputs
.
ModelRatio
))
{
showError
(
'模型倍率不是合法的 JSON 字符串'
);
showError
(
'模型倍率不是合法的 JSON 字符串'
);
...
@@ -287,6 +292,16 @@ const SystemSetting = () => {
...
@@ -287,6 +292,16 @@ const SystemSetting = () => {
type
=
'link'
type
=
'link'
placeholder
=
'例如发卡网站的购买链接'
placeholder
=
'例如发卡网站的购买链接'
/>
/>
<
Form
.
Input
label
=
'额度提醒阈值'
name
=
'QuotaRemindThreshold'
onChange
=
{
handleInputChange
}
autoComplete
=
'new-password'
value
=
{
inputs
.
QuotaRemindThreshold
}
type
=
'number'
min
=
'0'
placeholder
=
'低于此额度时将发送邮件提醒用户'
/>
<
/Form.Group
>
<
/Form.Group
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
TextArea
<
Form
.
TextArea
...
...
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