diff --git a/common/constants.go b/common/constants.go index f9595ee0..1ad0770d 100644 --- a/common/constants.go +++ b/common/constants.go @@ -51,9 +51,9 @@ var TurnstileSiteKey = "" var TurnstileSecretKey = "" var QuotaForNewUser = 100 - var ChannelDisableThreshold = 5.0 var AutomaticDisableChannelEnabled = false +var QuotaRemindThreshold = 1000 // TODO: QuotaRemindThreshold var RootUserEmail = "" diff --git a/model/option.go b/model/option.go index 5807ff03..14162420 100644 --- a/model/option.go +++ b/model/option.go @@ -54,6 +54,7 @@ func InitOptionMap() { common.OptionMap["TurnstileSiteKey"] = "" common.OptionMap["TurnstileSecretKey"] = "" common.OptionMap["QuotaForNewUser"] = strconv.Itoa(common.QuotaForNewUser) + common.OptionMap["QuotaRemindThreshold"] = strconv.Itoa(common.QuotaRemindThreshold) common.OptionMap["ModelRatio"] = common.ModelRatio2JSONString() common.OptionMap["TopUpLink"] = common.TopUpLink common.OptionMapRWMutex.Unlock() @@ -156,6 +157,8 @@ func updateOptionMap(key string, value string) (err error) { common.TurnstileSecretKey = value case "QuotaForNewUser": common.QuotaForNewUser, _ = strconv.Atoi(value) + case "QuotaRemindThreshold": + common.QuotaRemindThreshold, _ = strconv.Atoi(value) case "ModelRatio": err = common.UpdateModelRatioByJSONString(value) case "TopUpLink": diff --git a/web/src/components/OtherSetting.js b/web/src/components/OtherSetting.js index 0700d0b8..1ea5bf8f 100644 --- a/web/src/components/OtherSetting.js +++ b/web/src/components/OtherSetting.js @@ -12,7 +12,6 @@ const OtherSetting = () => { Logo: '', HomePageContent: '', }); - let originInputs = {}; let [loading, setLoading] = useState(false); const [showUpdateModal, setShowUpdateModal] = useState(false); const [updateData, setUpdateData] = useState({ @@ -21,7 +20,7 @@ const OtherSetting = () => { }); const getOptions = async () => { - const res = await API.get('/api/option'); + const res = await API.get('/api/option/'); const { success, message, data } = res.data; if (success) { let newInputs = {}; @@ -31,7 +30,6 @@ const OtherSetting = () => { } }); setInputs(newInputs); - originInputs = newInputs; } else { showError(message); } @@ -43,7 +41,7 @@ const OtherSetting = () => { const updateOption = async (key, value) => { setLoading(true); - const res = await API.put('/api/option', { + const res = await API.put('/api/option/', { key, value, }); diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index 405303a9..d71d8815 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -27,16 +27,17 @@ const SystemSetting = () => { TurnstileSecretKey: '', RegisterEnabled: '', QuotaForNewUser: 0, + QuotaRemindThreshold: 0, ModelRatio: '', TopUpLink: '', AutomaticDisableChannelEnabled: '', ChannelDisableThreshold: 0, }); - let originInputs = {}; + const [originInputs, setOriginInputs] = useState({}); let [loading, setLoading] = useState(false); const getOptions = async () => { - const res = await API.get('/api/option'); + const res = await API.get('/api/option/'); const { success, message, data } = res.data; if (success) { let newInputs = {}; @@ -44,7 +45,7 @@ const SystemSetting = () => { newInputs[item.key] = item.value; }); setInputs(newInputs); - originInputs = newInputs; + setOriginInputs(newInputs); } else { showError(message); } @@ -70,7 +71,7 @@ const SystemSetting = () => { default: break; } - const res = await API.put('/api/option', { + const res = await API.put('/api/option/', { key, value }); @@ -96,6 +97,7 @@ const SystemSetting = () => { name === 'TurnstileSiteKey' || name === 'TurnstileSecretKey' || name === 'QuotaForNewUser' || + name === 'QuotaRemindThreshold' || name === 'ModelRatio' || name === 'TopUpLink' ) { @@ -114,6 +116,9 @@ const SystemSetting = () => { if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) { await updateOption('QuotaForNewUser', inputs.QuotaForNewUser); } + if (originInputs['QuotaRemindThreshold'] !== inputs.QuotaRemindThreshold) { + await updateOption('QuotaRemindThreshold', inputs.QuotaRemindThreshold); + } if (originInputs['ModelRatio'] !== inputs.ModelRatio) { if (!verifyJSON(inputs.ModelRatio)) { showError('模型倍率不是合法的 JSON 字符串'); @@ -287,6 +292,16 @@ const SystemSetting = () => { type='link' placeholder='例如发卡网站的购买链接' /> +