Commit cee6f9c3 by CaIon

feat: 允许开关mj回调

parent 643622eb
package constant package constant
var MjNotifyEnabled = false
const ( const (
MjErrorUnknown = 5 MjErrorUnknown = 5
MjRequestError = 4 MjRequestError = 4
......
...@@ -2,6 +2,7 @@ package model ...@@ -2,6 +2,7 @@ package model
import ( import (
"one-api/common" "one-api/common"
"one-api/constant"
"strconv" "strconv"
"strings" "strings"
"time" "time"
...@@ -88,6 +89,7 @@ func InitOptionMap() { ...@@ -88,6 +89,7 @@ func InitOptionMap() {
common.OptionMap["DataExportInterval"] = strconv.Itoa(common.DataExportInterval) common.OptionMap["DataExportInterval"] = strconv.Itoa(common.DataExportInterval)
common.OptionMap["DataExportDefaultTime"] = common.DataExportDefaultTime common.OptionMap["DataExportDefaultTime"] = common.DataExportDefaultTime
common.OptionMap["DefaultCollapseSidebar"] = strconv.FormatBool(common.DefaultCollapseSidebar) common.OptionMap["DefaultCollapseSidebar"] = strconv.FormatBool(common.DefaultCollapseSidebar)
common.OptionMap["MjNotifyEnabled"] = strconv.FormatBool(constant.MjNotifyEnabled)
common.OptionMapRWMutex.Unlock() common.OptionMapRWMutex.Unlock()
loadOptionsFromDatabase() loadOptionsFromDatabase()
...@@ -181,6 +183,8 @@ func updateOptionMap(key string, value string) (err error) { ...@@ -181,6 +183,8 @@ func updateOptionMap(key string, value string) (err error) {
common.DataExportEnabled = boolValue common.DataExportEnabled = boolValue
case "DefaultCollapseSidebar": case "DefaultCollapseSidebar":
common.DefaultCollapseSidebar = boolValue common.DefaultCollapseSidebar = boolValue
case "MjNotifyEnabled":
constant.MjNotifyEnabled = boolValue
} }
} }
switch key { switch key {
......
...@@ -163,7 +163,9 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU ...@@ -163,7 +163,9 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "read_request_body_failed", http.StatusInternalServerError), nullBytes, err return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "read_request_body_failed", http.StatusInternalServerError), nullBytes, err
} }
delete(mapResult, "accountFilter") delete(mapResult, "accountFilter")
if !constant.MjNotifyEnabled {
delete(mapResult, "notifyHook") delete(mapResult, "notifyHook")
}
//req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody) //req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody)
// make new request with mapResult // make new request with mapResult
reqBody, err := json.Marshal(mapResult) reqBody, err := json.Marshal(mapResult)
......
...@@ -23,6 +23,7 @@ const OperationSetting = () => { ...@@ -23,6 +23,7 @@ const OperationSetting = () => {
LogConsumeEnabled: '', LogConsumeEnabled: '',
DisplayInCurrencyEnabled: '', DisplayInCurrencyEnabled: '',
DisplayTokenStatEnabled: '', DisplayTokenStatEnabled: '',
MjNotifyEnabled: '',
DrawingEnabled: '', DrawingEnabled: '',
DataExportEnabled: '', DataExportEnabled: '',
DataExportDefaultTime: 'hour', DataExportDefaultTime: 'hour',
...@@ -229,7 +230,6 @@ const OperationSetting = () => { ...@@ -229,7 +230,6 @@ const OperationSetting = () => {
/> />
</Form.Group> </Form.Group>
<Form.Group inline> <Form.Group inline>
<Form.Checkbox <Form.Checkbox
checked={inputs.DisplayInCurrencyEnabled === 'true'} checked={inputs.DisplayInCurrencyEnabled === 'true'}
label='以货币形式显示额度' label='以货币形式显示额度'
...@@ -243,21 +243,34 @@ const OperationSetting = () => { ...@@ -243,21 +243,34 @@ const OperationSetting = () => {
onChange={handleInputChange} onChange={handleInputChange}
/> />
<Form.Checkbox <Form.Checkbox
checked={inputs.DefaultCollapseSidebar === 'true'}
label='默认折叠侧边栏'
name='DefaultCollapseSidebar'
onChange={handleInputChange}
/>
</Form.Group>
<Form.Button onClick={() => {
submitConfig('general').then();
}}>保存通用设置</Form.Button>
<Divider/>
<Header as='h3'>
绘图设置
</Header>
<Form.Group inline>
<Form.Checkbox
checked={inputs.DrawingEnabled === 'true'} checked={inputs.DrawingEnabled === 'true'}
label='启用绘图功能' label='启用绘图功能'
name='DrawingEnabled' name='DrawingEnabled'
onChange={handleInputChange} onChange={handleInputChange}
/> />
<Form.Checkbox <Form.Checkbox
checked={inputs.DefaultCollapseSidebar === 'true'} checked={inputs.MjNotifyEnabled === 'true'}
label='默认折叠侧边栏' label='允许回调(会泄露服务器ip地址)'
name='DefaultCollapseSidebar' name='MjNotifyEnabled'
onChange={handleInputChange} onChange={handleInputChange}
/> />
</Form.Group> </Form.Group>
<Form.Button onClick={() => { <Divider/>
submitConfig('general').then();
}}>保存通用设置</Form.Button><Divider/>
<Header as='h3'> <Header as='h3'>
日志设置 日志设置
</Header> </Header>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment