From f97c2b4c22647e189f91eda2fcb23e4abf817e8e Mon Sep 17 00:00:00 2001 From: JustSong Date: Thu, 27 Apr 2023 16:32:21 +0800 Subject: [PATCH] feat: able to set top up link now --- README.md | 20 ++++++++++++-------- common/constants.go | 1 + controller/misc.go | 1 + model/option.go | 3 +++ web/src/components/SystemSetting.js | 28 +++++++++++++++++++++++----- web/src/components/TokensTable.js | 13 +++++++++++++ 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 250439f6..fae8bf45 100644 --- a/README.md +++ b/README.md @@ -52,14 +52,18 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用 + [x] 自定义渠道 2. 支持通过负载均衡的方式访问多个渠道。 3. 支持单个访问渠道设置多个 API Key,利用起来你的多个 API Key。 -4. 支持设置令牌的过期时间和使用次数。 -5. 支持 HTTP SSE。 -6. 多种用户登录注册方式: - + 邮箱登录注册以及通过邮箱进行密码重置。 - + [GitHub 开放授权](https://github.com/settings/applications/new)。 - + 微信公众号授权(需要额外部署 [WeChat Server](https://github.com/songquanpeng/wechat-server))。 -7. 支持用户管理。 -8. 未来其他大模型开放 API 后,将第一时间支持,并将其封装成同样的 API 访问方式。 +4. 支持 HTTP SSE,可以通过流式传输实现打字机效果。 +5. 支持设置令牌的过期时间和使用次数。 +6. 支持批量生成和导出兑换码,可使用兑换码为令牌进行充值。 +7. 支持为新用户设置初始配额。 +8. 支持发布公告,在线修改关于页面,设置充值链接,自定义页脚。 +9. 支持通过系统访问令牌访问管理 API。 +10. 多种用户登录注册方式: + + 邮箱登录注册以及通过邮箱进行密码重置。 + + [GitHub 开放授权](https://github.com/settings/applications/new)。 + + 微信公众号授权(需要额外部署 [WeChat Server](https://github.com/songquanpeng/wechat-server))。 +11. 支持用户管理。 +12. 未来其他大模型开放 API 后,将第一时间支持,并将其封装成同样的 API 访问方式。 ## 部署 ### 基于 Docker 进行部署 diff --git a/common/constants.go b/common/constants.go index 64e58748..e99e9a05 100644 --- a/common/constants.go +++ b/common/constants.go @@ -11,6 +11,7 @@ var Version = "v0.0.0" // this hard coding will be replaced automatic var SystemName = "One API" var ServerAddress = "http://localhost:3000" var Footer = "" +var TopUpLink = "" var UsingSQLite = false diff --git a/controller/misc.go b/controller/misc.go index aa5a77f8..837c1df4 100644 --- a/controller/misc.go +++ b/controller/misc.go @@ -26,6 +26,7 @@ func GetStatus(c *gin.Context) { "server_address": common.ServerAddress, "turnstile_check": common.TurnstileCheckEnabled, "turnstile_site_key": common.TurnstileSiteKey, + "top_up_link": common.TopUpLink, }, }) return diff --git a/model/option.go b/model/option.go index f06d1551..840ae000 100644 --- a/model/option.go +++ b/model/option.go @@ -47,6 +47,7 @@ func InitOptionMap() { common.OptionMap["TurnstileSiteKey"] = "" common.OptionMap["TurnstileSecretKey"] = "" common.OptionMap["QuotaForNewUser"] = strconv.Itoa(common.QuotaForNewUser) + common.OptionMap["TopUpLink"] = common.TopUpLink common.OptionMapRWMutex.Unlock() options, _ := AllOption() for _, option := range options { @@ -134,5 +135,7 @@ func updateOptionMap(key string, value string) { common.TurnstileSecretKey = value case "QuotaForNewUser": common.QuotaForNewUser, _ = strconv.Atoi(value) + case "TopUpLink": + common.TopUpLink = value } } diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index e0f1b105..124f4745 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -25,6 +25,7 @@ const SystemSetting = () => { TurnstileSecretKey: '', RegisterEnabled: '', QuotaForNewUser: 0, + TopUpLink: '' }); let originInputs = {}; let [loading, setLoading] = useState(false); @@ -65,7 +66,7 @@ const SystemSetting = () => { } const res = await API.put('/api/option', { key, - value, + value }); const { success, message } = res.data; if (success) { @@ -88,7 +89,8 @@ const SystemSetting = () => { name === 'WeChatAccountQRCodeImageURL' || name === 'TurnstileSiteKey' || name === 'TurnstileSecretKey' || - name === 'QuotaForNewUser' + name === 'QuotaForNewUser' || + name === 'TopUpLink' ) { setInputs((inputs) => ({ ...inputs, [name]: value })); } else { @@ -101,6 +103,15 @@ const SystemSetting = () => { await updateOption('ServerAddress', ServerAddress); }; + const submitOperationConfig = async () => { + if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) { + await updateOption('QuotaForNewUser', inputs.QuotaForNewUser); + } + if (originInputs['TopUpLink'] !== inputs.TopUpLink) { + await updateOption('TopUpLink', inputs.TopUpLink); + } + } + const submitSMTP = async () => { if (originInputs['SMTPServer'] !== inputs.SMTPServer) { await updateOption('SMTPServer', inputs.SMTPServer); @@ -244,10 +255,17 @@ const SystemSetting = () => { min='0' placeholder='例如:100' /> + - { - updateOption('QuotaForNewUser', inputs.QuotaForNewUser).then(); - }}>保存运营设置 + 保存运营设置
配置 SMTP diff --git a/web/src/components/TokensTable.js b/web/src/components/TokensTable.js index 795ea080..9f470735 100644 --- a/web/src/components/TokensTable.js +++ b/web/src/components/TokensTable.js @@ -37,6 +37,7 @@ const TokensTable = () => { const [showTopUpModal, setShowTopUpModal] = useState(false); const [targetTokenIdx, setTargetTokenIdx] = useState(0); const [redemptionCode, setRedemptionCode] = useState(''); + const [topUpLink, setTopUpLink] = useState(''); const loadTokens = async (startIdx) => { const res = await API.get(`/api/token/?p=${startIdx}`); @@ -71,6 +72,13 @@ const TokensTable = () => { .catch((reason) => { showError(reason); }); + let status = localStorage.getItem('status'); + if (status) { + status = JSON.parse(status); + if (status.top_up_link) { + setTopUpLink(status.top_up_link); + } + } }, []); const manageToken = async (id, action, idx) => { @@ -342,6 +350,11 @@ const TokensTable = () => { {/**/} + { + topUpLink &&

+ 点击此处获取兑换码 +

+ }