fix: legal setting

This commit is contained in:
Seefs
2025-10-10 13:18:26 +08:00
parent b7725d7ae1
commit 56ffbd57b9
6 changed files with 71 additions and 26 deletions

View File

@@ -5,4 +5,5 @@
.gitignore .gitignore
Makefile Makefile
docs docs
.eslintcache .eslintcache
.gocache

1
.gitignore vendored
View File

@@ -13,6 +13,7 @@ new-api
.DS_Store .DS_Store
tiktoken_cache tiktoken_cache
.eslintcache .eslintcache
.gocache
electron/node_modules electron/node_modules
electron/dist electron/dist

View File

@@ -43,6 +43,7 @@ func GetStatus(c *gin.Context) {
defer common.OptionMapRWMutex.RUnlock() defer common.OptionMapRWMutex.RUnlock()
passkeySetting := system_setting.GetPasskeySettings() passkeySetting := system_setting.GetPasskeySettings()
legalSetting := system_setting.GetLegalSettings()
data := gin.H{ data := gin.H{
"version": common.Version, "version": common.Version,
@@ -108,8 +109,8 @@ func GetStatus(c *gin.Context) {
"passkey_user_verification": passkeySetting.UserVerification, "passkey_user_verification": passkeySetting.UserVerification,
"passkey_attachment": passkeySetting.AttachmentPreference, "passkey_attachment": passkeySetting.AttachmentPreference,
"setup": constant.Setup, "setup": constant.Setup,
"user_agreement_enabled": common.OptionMap["UserAgreement"] != "", "user_agreement_enabled": legalSetting.UserAgreement != "",
"privacy_policy_enabled": common.OptionMap["PrivacyPolicy"] != "", "privacy_policy_enabled": legalSetting.PrivacyPolicy != "",
} }
// 根据启用状态注入可选内容 // 根据启用状态注入可选内容
@@ -154,23 +155,19 @@ func GetAbout(c *gin.Context) {
} }
func GetUserAgreement(c *gin.Context) { func GetUserAgreement(c *gin.Context) {
common.OptionMapRWMutex.RLock()
defer common.OptionMapRWMutex.RUnlock()
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"success": true, "success": true,
"message": "", "message": "",
"data": common.OptionMap["UserAgreement"], "data": system_setting.GetLegalSettings().UserAgreement,
}) })
return return
} }
func GetPrivacyPolicy(c *gin.Context) { func GetPrivacyPolicy(c *gin.Context) {
common.OptionMapRWMutex.RLock()
defer common.OptionMapRWMutex.RUnlock()
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"success": true, "success": true,
"message": "", "message": "",
"data": common.OptionMap["PrivacyPolicy"], "data": system_setting.GetLegalSettings().PrivacyPolicy,
}) })
return return
} }

View File

@@ -61,8 +61,6 @@ func InitOptionMap() {
common.OptionMap["SMTPToken"] = "" common.OptionMap["SMTPToken"] = ""
common.OptionMap["SMTPSSLEnabled"] = strconv.FormatBool(common.SMTPSSLEnabled) common.OptionMap["SMTPSSLEnabled"] = strconv.FormatBool(common.SMTPSSLEnabled)
common.OptionMap["Notice"] = "" common.OptionMap["Notice"] = ""
common.OptionMap["UserAgreement"] = ""
common.OptionMap["PrivacyPolicy"] = ""
common.OptionMap["About"] = "" common.OptionMap["About"] = ""
common.OptionMap["HomePageContent"] = "" common.OptionMap["HomePageContent"] = ""
common.OptionMap["Footer"] = common.Footer common.OptionMap["Footer"] = common.Footer

View File

@@ -0,0 +1,21 @@
package system_setting
import "one-api/setting/config"
type LegalSettings struct {
UserAgreement string `json:"user_agreement"`
PrivacyPolicy string `json:"privacy_policy"`
}
var defaultLegalSettings = LegalSettings{
UserAgreement: "",
PrivacyPolicy: "",
}
func init() {
config.GlobalConfig.Register("legal", &defaultLegalSettings)
}
func GetLegalSettings() *LegalSettings {
return &defaultLegalSettings
}

View File

@@ -34,12 +34,15 @@ import { useTranslation } from 'react-i18next';
import { StatusContext } from '../../context/Status'; import { StatusContext } from '../../context/Status';
import Text from '@douyinfe/semi-ui/lib/es/typography/text'; import Text from '@douyinfe/semi-ui/lib/es/typography/text';
const LEGAL_USER_AGREEMENT_KEY = 'legal.user_agreement';
const LEGAL_PRIVACY_POLICY_KEY = 'legal.privacy_policy';
const OtherSetting = () => { const OtherSetting = () => {
const { t } = useTranslation(); const { t } = useTranslation();
let [inputs, setInputs] = useState({ let [inputs, setInputs] = useState({
Notice: '', Notice: '',
UserAgreement: '', [LEGAL_USER_AGREEMENT_KEY]: '',
PrivacyPolicy: '', [LEGAL_PRIVACY_POLICY_KEY]: '',
SystemName: '', SystemName: '',
Logo: '', Logo: '',
Footer: '', Footer: '',
@@ -71,8 +74,8 @@ const OtherSetting = () => {
const [loadingInput, setLoadingInput] = useState({ const [loadingInput, setLoadingInput] = useState({
Notice: false, Notice: false,
UserAgreement: false, [LEGAL_USER_AGREEMENT_KEY]: false,
PrivacyPolicy: false, [LEGAL_PRIVACY_POLICY_KEY]: false,
SystemName: false, SystemName: false,
Logo: false, Logo: false,
HomePageContent: false, HomePageContent: false,
@@ -103,27 +106,45 @@ const OtherSetting = () => {
// 通用设置 - UserAgreement // 通用设置 - UserAgreement
const submitUserAgreement = async () => { const submitUserAgreement = async () => {
try { try {
setLoadingInput((loadingInput) => ({ ...loadingInput, UserAgreement: true })); setLoadingInput((loadingInput) => ({
await updateOption('UserAgreement', inputs.UserAgreement); ...loadingInput,
[LEGAL_USER_AGREEMENT_KEY]: true,
}));
await updateOption(
LEGAL_USER_AGREEMENT_KEY,
inputs[LEGAL_USER_AGREEMENT_KEY],
);
showSuccess(t('用户协议已更新')); showSuccess(t('用户协议已更新'));
} catch (error) { } catch (error) {
console.error(t('用户协议更新失败'), error); console.error(t('用户协议更新失败'), error);
showError(t('用户协议更新失败')); showError(t('用户协议更新失败'));
} finally { } finally {
setLoadingInput((loadingInput) => ({ ...loadingInput, UserAgreement: false })); setLoadingInput((loadingInput) => ({
...loadingInput,
[LEGAL_USER_AGREEMENT_KEY]: false,
}));
} }
}; };
// 通用设置 - PrivacyPolicy // 通用设置 - PrivacyPolicy
const submitPrivacyPolicy = async () => { const submitPrivacyPolicy = async () => {
try { try {
setLoadingInput((loadingInput) => ({ ...loadingInput, PrivacyPolicy: true })); setLoadingInput((loadingInput) => ({
await updateOption('PrivacyPolicy', inputs.PrivacyPolicy); ...loadingInput,
[LEGAL_PRIVACY_POLICY_KEY]: true,
}));
await updateOption(
LEGAL_PRIVACY_POLICY_KEY,
inputs[LEGAL_PRIVACY_POLICY_KEY],
);
showSuccess(t('隐私政策已更新')); showSuccess(t('隐私政策已更新'));
} catch (error) { } catch (error) {
console.error(t('隐私政策更新失败'), error); console.error(t('隐私政策更新失败'), error);
showError(t('隐私政策更新失败')); showError(t('隐私政策更新失败'));
} finally { } finally {
setLoadingInput((loadingInput) => ({ ...loadingInput, PrivacyPolicy: false })); setLoadingInput((loadingInput) => ({
...loadingInput,
[LEGAL_PRIVACY_POLICY_KEY]: false,
}));
} }
}; };
// 个性化设置 // 个性化设置
@@ -357,15 +378,18 @@ const OtherSetting = () => {
<Form.TextArea <Form.TextArea
label={t('用户协议')} label={t('用户协议')}
placeholder={t( placeholder={t(
'在此输入用户协议内容,支持 Markdown & HTML 代码', '在此输入用户协议内容,支持 Markdown & HTML 代码',
)} )}
field={'UserAgreement'} field={LEGAL_USER_AGREEMENT_KEY}
onChange={handleInputChange} onChange={handleInputChange}
style={{ fontFamily: 'JetBrains Mono, Consolas' }} style={{ fontFamily: 'JetBrains Mono, Consolas' }}
autosize={{ minRows: 6, maxRows: 12 }} autosize={{ minRows: 6, maxRows: 12 }}
helpText={t('填写用户协议内容后,用户注册时将被要求勾选已阅读用户协议')} helpText={t('填写用户协议内容后,用户注册时将被要求勾选已阅读用户协议')}
/> />
<Button onClick={submitUserAgreement} loading={loadingInput['UserAgreement']}> <Button
onClick={submitUserAgreement}
loading={loadingInput[LEGAL_USER_AGREEMENT_KEY]}
>
{t('设置用户协议')} {t('设置用户协议')}
</Button> </Button>
<Form.TextArea <Form.TextArea
@@ -373,13 +397,16 @@ const OtherSetting = () => {
placeholder={t( placeholder={t(
'在此输入隐私政策内容,支持 Markdown & HTML 代码', '在此输入隐私政策内容,支持 Markdown & HTML 代码',
)} )}
field={'PrivacyPolicy'} field={LEGAL_PRIVACY_POLICY_KEY}
onChange={handleInputChange} onChange={handleInputChange}
style={{ fontFamily: 'JetBrains Mono, Consolas' }} style={{ fontFamily: 'JetBrains Mono, Consolas' }}
autosize={{ minRows: 6, maxRows: 12 }} autosize={{ minRows: 6, maxRows: 12 }}
helpText={t('填写隐私政策内容后,用户注册时将被要求勾选已阅读隐私政策')} helpText={t('填写隐私政策内容后,用户注册时将被要求勾选已阅读隐私政策')}
/> />
<Button onClick={submitPrivacyPolicy} loading={loadingInput['PrivacyPolicy']}> <Button
onClick={submitPrivacyPolicy}
loading={loadingInput[LEGAL_PRIVACY_POLICY_KEY]}
>
{t('设置隐私政策')} {t('设置隐私政策')}
</Button> </Button>
</Form.Section> </Form.Section>