✨ feat: Enhance user settings and notification options
This commit is contained in:
@@ -6,6 +6,7 @@ var (
|
||||
UserSettingWebhookUrl = "webhook_url" // WebhookUrl webhook地址
|
||||
UserSettingWebhookSecret = "webhook_secret" // WebhookSecret webhook密钥
|
||||
UserSettingNotificationEmail = "notification_email" // NotificationEmail 通知邮箱地址
|
||||
UserAcceptUnsetRatioModel = "accept_unset_model_ratio_model" // AcceptUnsetRatioModel 是否接受未设置价格的模型
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -105,6 +105,11 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
|
||||
request := buildTestRequest(testModel)
|
||||
common.SysLog(fmt.Sprintf("testing channel %d with model %s , info %v ", channel.Id, testModel, info))
|
||||
|
||||
priceData, err := helper.ModelPriceHelper(c, info, 0, int(request.MaxTokens))
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
adaptor.Init(info)
|
||||
|
||||
convertedRequest, err := adaptor.ConvertOpenAIRequest(c, info, request)
|
||||
@@ -143,10 +148,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
|
||||
return err, nil
|
||||
}
|
||||
info.PromptTokens = usage.PromptTokens
|
||||
priceData, err := helper.ModelPriceHelper(c, info, usage.PromptTokens, int(request.MaxTokens))
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
quota := 0
|
||||
if !priceData.UsePrice {
|
||||
quota = usage.PromptTokens + int(math.Round(float64(usage.CompletionTokens)*priceData.CompletionRatio))
|
||||
|
||||
@@ -918,6 +918,7 @@ type UpdateUserSettingRequest struct {
|
||||
WebhookUrl string `json:"webhook_url,omitempty"`
|
||||
WebhookSecret string `json:"webhook_secret,omitempty"`
|
||||
NotificationEmail string `json:"notification_email,omitempty"`
|
||||
AcceptUnsetModelRatioModel bool `json:"accept_unset_model_ratio_model"`
|
||||
}
|
||||
|
||||
func UpdateUserSetting(c *gin.Context) {
|
||||
@@ -993,6 +994,7 @@ func UpdateUserSetting(c *gin.Context) {
|
||||
settings := map[string]interface{}{
|
||||
constant.UserSettingNotifyType: req.QuotaWarningType,
|
||||
constant.UserSettingQuotaWarningThreshold: req.QuotaWarningThreshold,
|
||||
"accept_unset_model_ratio_model": req.AcceptUnsetModelRatioModel,
|
||||
}
|
||||
|
||||
// 如果是webhook类型,添加webhook相关设置
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"one-api/common"
|
||||
constant2 "one-api/constant"
|
||||
relaycommon "one-api/relay/common"
|
||||
"one-api/setting"
|
||||
"one-api/setting/operation_setting"
|
||||
@@ -40,12 +41,21 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
|
||||
var success bool
|
||||
modelRatio, success = operation_setting.GetModelRatio(info.OriginModelName)
|
||||
if !success {
|
||||
acceptUnsetRatio := false
|
||||
if accept, ok := info.UserSetting[constant2.UserAcceptUnsetRatioModel]; ok {
|
||||
b, ok := accept.(bool)
|
||||
if ok {
|
||||
acceptUnsetRatio = b
|
||||
}
|
||||
}
|
||||
if !acceptUnsetRatio {
|
||||
if info.UserId == 1 {
|
||||
return PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置,请设置或开始自用模式;Model %s ratio or price not set, please set or start self-use mode", info.OriginModelName, info.OriginModelName)
|
||||
} else {
|
||||
return PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置, 请联系管理员设置;Model %s ratio or price not set, please contact administrator to set", info.OriginModelName, info.OriginModelName)
|
||||
}
|
||||
}
|
||||
}
|
||||
completionRatio = operation_setting.GetCompletionRatio(info.OriginModelName)
|
||||
cacheRatio, _ = operation_setting.GetCacheRatio(info.OriginModelName)
|
||||
cacheCreationRatio, _ = operation_setting.GetCreateCacheRatio(info.OriginModelName)
|
||||
|
||||
5189
web/pnpm-lock.yaml
generated
5189
web/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,16 @@
|
||||
import React, {useContext, useEffect, useState} from 'react';
|
||||
import {useNavigate} from 'react-router-dom';
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
API,
|
||||
copy,
|
||||
isRoot,
|
||||
showError,
|
||||
showInfo,
|
||||
showSuccess,
|
||||
showSuccess
|
||||
} from '../helpers';
|
||||
import Turnstile from 'react-turnstile';
|
||||
import {UserContext} from '../context/User';
|
||||
import {onGitHubOAuthClicked, onOIDCClicked, onLinuxDOOAuthClicked} from './utils';
|
||||
import { UserContext } from '../context/User';
|
||||
import { onGitHubOAuthClicked, onOIDCClicked, onLinuxDOOAuthClicked } from './utils';
|
||||
import {
|
||||
Avatar,
|
||||
Banner,
|
||||
@@ -30,12 +30,15 @@ import {
|
||||
Radio,
|
||||
RadioGroup,
|
||||
AutoComplete,
|
||||
Checkbox,
|
||||
Tabs,
|
||||
TabPane
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
getQuotaPerUnit,
|
||||
renderQuota,
|
||||
renderQuotaWithPrompt,
|
||||
stringToColor,
|
||||
stringToColor
|
||||
} from '../helpers/render';
|
||||
import TelegramLoginButton from 'react-telegram-login';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -51,7 +54,7 @@ const PersonalSetting = () => {
|
||||
email: '',
|
||||
self_account_deletion_confirmation: '',
|
||||
set_new_password: '',
|
||||
set_new_password_confirmation: '',
|
||||
set_new_password_confirmation: ''
|
||||
});
|
||||
const [status, setStatus] = useState({});
|
||||
const [showChangePasswordModal, setShowChangePasswordModal] = useState(false);
|
||||
@@ -80,7 +83,8 @@ const PersonalSetting = () => {
|
||||
warningThreshold: 100000,
|
||||
webhookUrl: '',
|
||||
webhookSecret: '',
|
||||
notificationEmail: ''
|
||||
notificationEmail: '',
|
||||
acceptUnsetModelRatioModel: false
|
||||
});
|
||||
const [showWebhookDocs, setShowWebhookDocs] = useState(false);
|
||||
|
||||
@@ -123,7 +127,8 @@ const PersonalSetting = () => {
|
||||
warningThreshold: settings.quota_warning_threshold || 500000,
|
||||
webhookUrl: settings.webhook_url || '',
|
||||
webhookSecret: settings.webhook_secret || '',
|
||||
notificationEmail: settings.notification_email || ''
|
||||
notificationEmail: settings.notification_email || '',
|
||||
acceptUnsetModelRatioModel: settings.accept_unset_model_ratio_model || false
|
||||
});
|
||||
}
|
||||
}, [userState?.user?.setting]);
|
||||
@@ -134,12 +139,12 @@ const PersonalSetting = () => {
|
||||
}, [isModelsExpanded]);
|
||||
|
||||
const handleInputChange = (name, value) => {
|
||||
setInputs((inputs) => ({...inputs, [name]: value}));
|
||||
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
||||
};
|
||||
|
||||
const generateAccessToken = async () => {
|
||||
const res = await API.get('/api/user/token');
|
||||
const {success, message, data} = res.data;
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
setSystemToken(data);
|
||||
await copy(data);
|
||||
@@ -151,7 +156,7 @@ const PersonalSetting = () => {
|
||||
|
||||
const getAffLink = async () => {
|
||||
const res = await API.get('/api/user/aff');
|
||||
const {success, message, data} = res.data;
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
let link = `${window.location.origin}/register?aff=${data}`;
|
||||
setAffLink(link);
|
||||
@@ -162,9 +167,9 @@ const PersonalSetting = () => {
|
||||
|
||||
const getUserData = async () => {
|
||||
let res = await API.get(`/api/user/self`);
|
||||
const {success, message, data} = res.data;
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
userDispatch({type: 'login', payload: data});
|
||||
userDispatch({ type: 'login', payload: data });
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
@@ -172,7 +177,7 @@ const PersonalSetting = () => {
|
||||
|
||||
const loadModels = async () => {
|
||||
let res = await API.get(`/api/user/models`);
|
||||
const {success, message, data} = res.data;
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (data != null) {
|
||||
setModels(data);
|
||||
@@ -201,12 +206,12 @@ const PersonalSetting = () => {
|
||||
}
|
||||
|
||||
const res = await API.delete('/api/user/self');
|
||||
const {success, message} = res.data;
|
||||
const { success, message } = res.data;
|
||||
|
||||
if (success) {
|
||||
showSuccess(t('账户已删除!'));
|
||||
await API.get('/api/user/logout');
|
||||
userDispatch({type: 'logout'});
|
||||
userDispatch({ type: 'logout' });
|
||||
localStorage.removeItem('user');
|
||||
navigate('/login');
|
||||
} else {
|
||||
@@ -217,9 +222,9 @@ const PersonalSetting = () => {
|
||||
const bindWeChat = async () => {
|
||||
if (inputs.wechat_verification_code === '') return;
|
||||
const res = await API.get(
|
||||
`/api/oauth/wechat/bind?code=${inputs.wechat_verification_code}`,
|
||||
`/api/oauth/wechat/bind?code=${inputs.wechat_verification_code}`
|
||||
);
|
||||
const {success, message} = res.data;
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('微信账户绑定成功!'));
|
||||
setShowWeChatBindModal(false);
|
||||
@@ -234,9 +239,9 @@ const PersonalSetting = () => {
|
||||
return;
|
||||
}
|
||||
const res = await API.put(`/api/user/self`, {
|
||||
password: inputs.set_new_password,
|
||||
password: inputs.set_new_password
|
||||
});
|
||||
const {success, message} = res.data;
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('密码修改成功!'));
|
||||
setShowWeChatBindModal(false);
|
||||
@@ -252,9 +257,9 @@ const PersonalSetting = () => {
|
||||
return;
|
||||
}
|
||||
const res = await API.post(`/api/user/aff_transfer`, {
|
||||
quota: transferAmount,
|
||||
quota: transferAmount
|
||||
});
|
||||
const {success, message} = res.data;
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(message);
|
||||
setOpenTransfer(false);
|
||||
@@ -276,9 +281,9 @@ const PersonalSetting = () => {
|
||||
}
|
||||
setLoading(true);
|
||||
const res = await API.get(
|
||||
`/api/verification?email=${inputs.email}&turnstile=${turnstileToken}`,
|
||||
`/api/verification?email=${inputs.email}&turnstile=${turnstileToken}`
|
||||
);
|
||||
const {success, message} = res.data;
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('验证码发送成功,请检查邮箱!'));
|
||||
} else {
|
||||
@@ -294,9 +299,9 @@ const PersonalSetting = () => {
|
||||
}
|
||||
setLoading(true);
|
||||
const res = await API.get(
|
||||
`/api/oauth/email/bind?email=${inputs.email}&code=${inputs.email_verification_code}`,
|
||||
`/api/oauth/email/bind?email=${inputs.email}&code=${inputs.email_verification_code}`
|
||||
);
|
||||
const {success, message} = res.data;
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('邮箱账户绑定成功!'));
|
||||
setShowEmailBindModal(false);
|
||||
@@ -324,7 +329,7 @@ const PersonalSetting = () => {
|
||||
showSuccess(t('已复制:') + text);
|
||||
} else {
|
||||
// setSearchKeyword(text);
|
||||
Modal.error({title: t('无法复制到剪贴板,请手动复制'), content: text});
|
||||
Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: text });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -342,7 +347,8 @@ const PersonalSetting = () => {
|
||||
quota_warning_threshold: parseFloat(notificationSettings.warningThreshold),
|
||||
webhook_url: notificationSettings.webhookUrl,
|
||||
webhook_secret: notificationSettings.webhookSecret,
|
||||
notification_email: notificationSettings.notificationEmail
|
||||
notification_email: notificationSettings.notificationEmail,
|
||||
accept_unset_model_ratio_model: notificationSettings.acceptUnsetModelRatioModel
|
||||
});
|
||||
|
||||
if (res.data.success) {
|
||||
@@ -370,22 +376,22 @@ const PersonalSetting = () => {
|
||||
size={'small'}
|
||||
centered={true}
|
||||
>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text>{t('可用额度')}{renderQuotaWithPrompt(userState?.user?.aff_quota)}</Typography.Text>
|
||||
<Input
|
||||
style={{marginTop: 5}}
|
||||
style={{ marginTop: 5 }}
|
||||
value={userState?.user?.aff_quota}
|
||||
disabled={true}
|
||||
></Input>
|
||||
</div>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text>
|
||||
{t('划转额度')}{renderQuotaWithPrompt(transferAmount)} {t('最低') + renderQuota(getQuotaPerUnit())}
|
||||
</Typography.Text>
|
||||
<div>
|
||||
<InputNumber
|
||||
min={0}
|
||||
style={{marginTop: 5}}
|
||||
style={{ marginTop: 5 }}
|
||||
value={transferAmount}
|
||||
onChange={(value) => setTransferAmount(value)}
|
||||
disabled={false}
|
||||
@@ -399,9 +405,9 @@ const PersonalSetting = () => {
|
||||
<Card.Meta
|
||||
avatar={
|
||||
<Avatar
|
||||
size='default'
|
||||
size="default"
|
||||
color={stringToColor(getUsername())}
|
||||
style={{marginRight: 4}}
|
||||
style={{ marginRight: 4 }}
|
||||
>
|
||||
{typeof getUsername() === 'string' &&
|
||||
getUsername().slice(0, 1)}
|
||||
@@ -410,18 +416,18 @@ const PersonalSetting = () => {
|
||||
title={<Typography.Text>{getUsername()}</Typography.Text>}
|
||||
description={
|
||||
isRoot() ? (
|
||||
<Tag color='red'>{t('管理员')}</Tag>
|
||||
<Tag color="red">{t('管理员')}</Tag>
|
||||
) : (
|
||||
<Tag color='blue'>{t('普通用户')}</Tag>
|
||||
<Tag color="blue">{t('普通用户')}</Tag>
|
||||
)
|
||||
}
|
||||
></Card.Meta>
|
||||
}
|
||||
headerExtraContent={
|
||||
<>
|
||||
<Space vertical align='start'>
|
||||
<Tag color='green'>{'ID: ' + userState?.user?.id}</Tag>
|
||||
<Tag color='blue'>{userState?.user?.group}</Tag>
|
||||
<Space vertical align="start">
|
||||
<Tag color="green">{'ID: ' + userState?.user?.id}</Tag>
|
||||
<Tag color="blue">{userState?.user?.group}</Tag>
|
||||
</Space>
|
||||
</>
|
||||
}
|
||||
@@ -430,13 +436,13 @@ const PersonalSetting = () => {
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<Typography.Title heading={6}>{t('可用模型')}</Typography.Title>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
{models.length <= MODELS_DISPLAY_COUNT ? (
|
||||
<Space wrap>
|
||||
{models.map((model) => (
|
||||
<Tag
|
||||
key={model}
|
||||
color='cyan'
|
||||
color="cyan"
|
||||
onClick={() => {
|
||||
copyText(model);
|
||||
}}
|
||||
@@ -452,7 +458,7 @@ const PersonalSetting = () => {
|
||||
{models.map((model) => (
|
||||
<Tag
|
||||
key={model}
|
||||
color='cyan'
|
||||
color="cyan"
|
||||
onClick={() => {
|
||||
copyText(model);
|
||||
}}
|
||||
@@ -461,7 +467,7 @@ const PersonalSetting = () => {
|
||||
</Tag>
|
||||
))}
|
||||
<Tag
|
||||
color='blue'
|
||||
color="blue"
|
||||
type="light"
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => setIsModelsExpanded(false)}
|
||||
@@ -475,7 +481,7 @@ const PersonalSetting = () => {
|
||||
{models.slice(0, MODELS_DISPLAY_COUNT).map((model) => (
|
||||
<Tag
|
||||
key={model}
|
||||
color='cyan'
|
||||
color="cyan"
|
||||
onClick={() => {
|
||||
copyText(model);
|
||||
}}
|
||||
@@ -484,7 +490,7 @@ const PersonalSetting = () => {
|
||||
</Tag>
|
||||
))}
|
||||
<Tag
|
||||
color='blue'
|
||||
color="blue"
|
||||
type="light"
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => setIsModelsExpanded(true)}
|
||||
@@ -513,12 +519,12 @@ const PersonalSetting = () => {
|
||||
</Descriptions>
|
||||
</Card>
|
||||
<Card
|
||||
style={{marginTop: 10}}
|
||||
style={{ marginTop: 10 }}
|
||||
footer={
|
||||
<div>
|
||||
<Typography.Text>{t('邀请链接')}</Typography.Text>
|
||||
<Input
|
||||
style={{marginTop: 10}}
|
||||
style={{ marginTop: 10 }}
|
||||
value={affLink}
|
||||
onClick={handleAffLinkClick}
|
||||
readOnly
|
||||
@@ -527,17 +533,17 @@ const PersonalSetting = () => {
|
||||
}
|
||||
>
|
||||
<Typography.Title heading={6}>{t('邀请信息')}</Typography.Title>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Descriptions row>
|
||||
<Descriptions.Item itemKey={t('待使用收益')}>
|
||||
<span style={{color: 'rgba(var(--semi-red-5), 1)'}}>
|
||||
<span style={{ color: 'rgba(var(--semi-red-5), 1)' }}>
|
||||
{renderQuota(userState?.user?.aff_quota)}
|
||||
</span>
|
||||
<Button
|
||||
type={'secondary'}
|
||||
onClick={() => setOpenTransfer(true)}
|
||||
size={'small'}
|
||||
style={{marginLeft: 10}}
|
||||
style={{ marginLeft: 10 }}
|
||||
>
|
||||
{t('划转')}
|
||||
</Button>
|
||||
@@ -551,12 +557,12 @@ const PersonalSetting = () => {
|
||||
</Descriptions>
|
||||
</div>
|
||||
</Card>
|
||||
<Card style={{marginTop: 10}}>
|
||||
<Card style={{ marginTop: 10 }}>
|
||||
<Typography.Title heading={6}>{t('个人信息')}</Typography.Title>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text strong>{t('邮箱')}</Typography.Text>
|
||||
<div
|
||||
style={{display: 'flex', justifyContent: 'space-between'}}
|
||||
style={{ display: 'flex', justifyContent: 'space-between' }}
|
||||
>
|
||||
<div>
|
||||
<Input
|
||||
@@ -581,9 +587,9 @@ const PersonalSetting = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Typography.Text strong>{t('微信')}</Typography.Text>
|
||||
<div style={{display: 'flex', justifyContent: 'space-between'}}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<div>
|
||||
<Input
|
||||
value={
|
||||
@@ -610,10 +616,10 @@ const PersonalSetting = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Typography.Text strong>{t('GitHub')}</Typography.Text>
|
||||
<div
|
||||
style={{display: 'flex', justifyContent: 'space-between'}}
|
||||
style={{ display: 'flex', justifyContent: 'space-between' }}
|
||||
>
|
||||
<div>
|
||||
<Input
|
||||
@@ -640,10 +646,10 @@ const PersonalSetting = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Typography.Text strong>{t('OIDC')}</Typography.Text>
|
||||
<div
|
||||
style={{display: 'flex', justifyContent: 'space-between'}}
|
||||
style={{ display: 'flex', justifyContent: 'space-between' }}
|
||||
>
|
||||
<div>
|
||||
<Input
|
||||
@@ -670,10 +676,10 @@ const PersonalSetting = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Typography.Text strong>{t('Telegram')}</Typography.Text>
|
||||
<div
|
||||
style={{display: 'flex', justifyContent: 'space-between'}}
|
||||
style={{ display: 'flex', justifyContent: 'space-between' }}
|
||||
>
|
||||
<div>
|
||||
<Input
|
||||
@@ -691,7 +697,7 @@ const PersonalSetting = () => {
|
||||
<Button disabled={true}>{t('已绑定')}</Button>
|
||||
) : (
|
||||
<TelegramLoginButton
|
||||
dataAuthUrl='/api/oauth/telegram/bind'
|
||||
dataAuthUrl="/api/oauth/telegram/bind"
|
||||
botName={status.telegram_bot_name}
|
||||
/>
|
||||
)
|
||||
@@ -701,10 +707,10 @@ const PersonalSetting = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Typography.Text strong>{t('LinuxDO')}</Typography.Text>
|
||||
<div
|
||||
style={{display: 'flex', justifyContent: 'space-between'}}
|
||||
style={{ display: 'flex', justifyContent: 'space-between' }}
|
||||
>
|
||||
<div>
|
||||
<Input
|
||||
@@ -731,7 +737,7 @@ const PersonalSetting = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Space>
|
||||
<Button onClick={generateAccessToken}>
|
||||
{t('生成系统访问令牌')}
|
||||
@@ -758,7 +764,7 @@ const PersonalSetting = () => {
|
||||
readOnly
|
||||
value={systemToken}
|
||||
onClick={handleSystemTokenClick}
|
||||
style={{marginTop: '10px'}}
|
||||
style={{ marginTop: '10px' }}
|
||||
/>
|
||||
)}
|
||||
<Modal
|
||||
@@ -766,31 +772,48 @@ const PersonalSetting = () => {
|
||||
visible={showWeChatBindModal}
|
||||
size={'small'}
|
||||
>
|
||||
<Image src={status.wechat_qrcode}/>
|
||||
<div style={{textAlign: 'center'}}>
|
||||
<Image src={status.wechat_qrcode} />
|
||||
<div style={{ textAlign: 'center' }}>
|
||||
<p>
|
||||
微信扫码关注公众号,输入「验证码」获取验证码(三分钟内有效)
|
||||
</p>
|
||||
</div>
|
||||
<Input
|
||||
placeholder='验证码'
|
||||
name='wechat_verification_code'
|
||||
placeholder="验证码"
|
||||
name="wechat_verification_code"
|
||||
value={inputs.wechat_verification_code}
|
||||
onChange={(v) =>
|
||||
handleInputChange('wechat_verification_code', v)
|
||||
}
|
||||
/>
|
||||
<Button color='' fluid size='large' onClick={bindWeChat}>
|
||||
<Button color="" fluid size="large" onClick={bindWeChat}>
|
||||
{t('绑定')}
|
||||
</Button>
|
||||
</Modal>
|
||||
</div>
|
||||
</Card>
|
||||
<Card style={{marginTop: 10}}>
|
||||
<Typography.Title heading={6}>{t('通知设置')}</Typography.Title>
|
||||
<div style={{marginTop: 20}}>
|
||||
<Card style={{ marginTop: 10 }}>
|
||||
<Tabs type="line" defaultActiveKey="price">
|
||||
<TabPane tab={t('价格设置')} itemKey="price">
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text strong>{t('接受未设置价格模型')}</Typography.Text>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Checkbox
|
||||
checked={notificationSettings.acceptUnsetModelRatioModel}
|
||||
onChange={e => handleNotificationSettingChange('acceptUnsetModelRatioModel', e.target.checked)}
|
||||
>
|
||||
{t('接受未设置价格模型')}
|
||||
</Checkbox>
|
||||
<Typography.Text type="secondary" style={{ marginTop: 8, display: 'block' }}>
|
||||
{t('当模型没有设置价格时仍接受调用,仅当您信任该网站时使用,可能会产生高额费用')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
</TabPane>
|
||||
<TabPane tab={t('通知设置')} itemKey="notification">
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text strong>{t('通知方式')}</Typography.Text>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<RadioGroup
|
||||
value={notificationSettings.warningType}
|
||||
onChange={value => handleNotificationSettingChange('warningType', value)}
|
||||
@@ -802,23 +825,28 @@ const PersonalSetting = () => {
|
||||
</div>
|
||||
{notificationSettings.warningType === 'webhook' && (
|
||||
<>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text strong>{t('Webhook地址')}</Typography.Text>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Input
|
||||
value={notificationSettings.webhookUrl}
|
||||
onChange={val => handleNotificationSettingChange('webhookUrl', val)}
|
||||
placeholder={t('请输入Webhook地址,例如: https://example.com/webhook')}
|
||||
/>
|
||||
<Typography.Text type="secondary" style={{marginTop: 8, display: 'block'}}>
|
||||
<Typography.Text type="secondary" style={{ marginTop: 8, display: 'block' }}>
|
||||
{t('只支持https,系统将以 POST 方式发送通知,请确保地址可以接收 POST 请求')}
|
||||
</Typography.Text>
|
||||
<Typography.Text type="secondary" style={{marginTop: 8, display: 'block'}}>
|
||||
<div style={{cursor: 'pointer'}} onClick={() => setShowWebhookDocs(!showWebhookDocs)}>
|
||||
<Typography.Text type="secondary" style={{ marginTop: 8, display: 'block' }}>
|
||||
<div style={{ cursor: 'pointer' }} onClick={() => setShowWebhookDocs(!showWebhookDocs)}>
|
||||
{t('Webhook请求结构')} {showWebhookDocs ? '▼' : '▶'}
|
||||
</div>
|
||||
<Collapsible isOpen={showWebhookDocs}>
|
||||
<pre style={{marginTop: 4, background: 'var(--semi-color-fill-0)', padding: 8, borderRadius: 4}}>
|
||||
<pre style={{
|
||||
marginTop: 4,
|
||||
background: 'var(--semi-color-fill-0)',
|
||||
padding: 8,
|
||||
borderRadius: 4
|
||||
}}>
|
||||
{`{
|
||||
"type": "quota_exceed", // 通知类型
|
||||
"title": "标题", // 通知标题
|
||||
@@ -840,18 +868,18 @@ const PersonalSetting = () => {
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text strong>{t('接口凭证(可选)')}</Typography.Text>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Input
|
||||
value={notificationSettings.webhookSecret}
|
||||
onChange={val => handleNotificationSettingChange('webhookSecret', val)}
|
||||
placeholder={t('请输入密钥')}
|
||||
/>
|
||||
<Typography.Text type="secondary" style={{marginTop: 8, display: 'block'}}>
|
||||
<Typography.Text type="secondary" style={{ marginTop: 8, display: 'block' }}>
|
||||
{t('密钥将以 Bearer 方式添加到请求头中,用于验证webhook请求的合法性')}
|
||||
</Typography.Text>
|
||||
<Typography.Text type="secondary" style={{marginTop: 4, display: 'block'}}>
|
||||
<Typography.Text type="secondary" style={{ marginTop: 4, display: 'block' }}>
|
||||
{t('Authorization: Bearer your-secret-key')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
@@ -859,27 +887,28 @@ const PersonalSetting = () => {
|
||||
</>
|
||||
)}
|
||||
{notificationSettings.warningType === 'email' && (
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text strong>{t('通知邮箱')}</Typography.Text>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Input
|
||||
value={notificationSettings.notificationEmail}
|
||||
onChange={val => handleNotificationSettingChange('notificationEmail', val)}
|
||||
placeholder={t('留空则使用账号绑定的邮箱')}
|
||||
/>
|
||||
<Typography.Text type="secondary" style={{marginTop: 8, display: 'block'}}>
|
||||
<Typography.Text type="secondary" style={{ marginTop: 8, display: 'block' }}>
|
||||
{t('设置用于接收额度预警的邮箱地址,不填则使用账号绑定的邮箱')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div style={{marginTop: 20}}>
|
||||
<Typography.Text strong>{t('额度预警阈值')} {renderQuotaWithPrompt(notificationSettings.warningThreshold)}</Typography.Text>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Typography.Text
|
||||
strong>{t('额度预警阈值')} {renderQuotaWithPrompt(notificationSettings.warningThreshold)}</Typography.Text>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<AutoComplete
|
||||
value={notificationSettings.warningThreshold}
|
||||
onChange={val => handleNotificationSettingChange('warningThreshold', val)}
|
||||
style={{width: 200}}
|
||||
style={{ width: 200 }}
|
||||
placeholder={t('请输入预警额度')}
|
||||
data={[
|
||||
{ value: 100000, label: '0.2$' },
|
||||
@@ -889,11 +918,13 @@ const PersonalSetting = () => {
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<Typography.Text type="secondary" style={{marginTop: 10, display: 'block'}}>
|
||||
<Typography.Text type="secondary" style={{ marginTop: 10, display: 'block' }}>
|
||||
{t('当剩余额度低于此数值时,系统将通过选择的方式发送通知')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
<div style={{marginTop: 20}}>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Button type="primary" onClick={saveNotificationSettings}>
|
||||
{t('保存设置')}
|
||||
</Button>
|
||||
@@ -912,15 +943,15 @@ const PersonalSetting = () => {
|
||||
style={{
|
||||
marginTop: 20,
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
justifyContent: 'space-between'
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
fluid
|
||||
placeholder='输入邮箱地址'
|
||||
placeholder="输入邮箱地址"
|
||||
onChange={(value) => handleInputChange('email', value)}
|
||||
name='email'
|
||||
type='email'
|
||||
name="email"
|
||||
type="email"
|
||||
/>
|
||||
<Button
|
||||
onClick={sendVerificationCode}
|
||||
@@ -929,11 +960,11 @@ const PersonalSetting = () => {
|
||||
{disableButton ? `重新发送 (${countdown})` : '获取验证码'}
|
||||
</Button>
|
||||
</div>
|
||||
<div style={{marginTop: 10}}>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Input
|
||||
fluid
|
||||
placeholder='验证码'
|
||||
name='email_verification_code'
|
||||
placeholder="验证码"
|
||||
name="email_verification_code"
|
||||
value={inputs.email_verification_code}
|
||||
onChange={(value) =>
|
||||
handleInputChange('email_verification_code', value)
|
||||
@@ -958,22 +989,22 @@ const PersonalSetting = () => {
|
||||
centered={true}
|
||||
onOk={deleteAccount}
|
||||
>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Banner
|
||||
type='danger'
|
||||
description='您正在删除自己的帐户,将清空所有数据且不可恢复'
|
||||
type="danger"
|
||||
description="您正在删除自己的帐户,将清空所有数据且不可恢复"
|
||||
closeIcon={null}
|
||||
/>
|
||||
</div>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Input
|
||||
placeholder={`输入你的账户名 ${userState?.user?.username} 以确认删除`}
|
||||
name='self_account_deletion_confirmation'
|
||||
name="self_account_deletion_confirmation"
|
||||
value={inputs.self_account_deletion_confirmation}
|
||||
onChange={(value) =>
|
||||
handleInputChange(
|
||||
'self_account_deletion_confirmation',
|
||||
value,
|
||||
value
|
||||
)
|
||||
}
|
||||
/>
|
||||
@@ -996,9 +1027,9 @@ const PersonalSetting = () => {
|
||||
centered={true}
|
||||
onOk={changePassword}
|
||||
>
|
||||
<div style={{marginTop: 20}}>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<Input
|
||||
name='set_new_password'
|
||||
name="set_new_password"
|
||||
placeholder={t('新密码')}
|
||||
value={inputs.set_new_password}
|
||||
onChange={(value) =>
|
||||
@@ -1006,8 +1037,8 @@ const PersonalSetting = () => {
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
style={{marginTop: 20}}
|
||||
name='set_new_password_confirmation'
|
||||
style={{ marginTop: 20 }}
|
||||
name="set_new_password_confirmation"
|
||||
placeholder={t('确认新密码')}
|
||||
value={inputs.set_new_password_confirmation}
|
||||
onChange={(value) =>
|
||||
|
||||
Reference in New Issue
Block a user