diff --git a/.dockerignore b/.dockerignore index 0670cd7d1..781a7b550 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,4 +5,5 @@ .gitignore Makefile docs -.eslintcache \ No newline at end of file +.eslintcache +.gocache \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3e6020e83..0cf4ce09a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ new-api .DS_Store tiktoken_cache .eslintcache +.gocache electron/node_modules electron/dist \ No newline at end of file diff --git a/controller/misc.go b/controller/misc.go index c6c54b6d1..8654848d5 100644 --- a/controller/misc.go +++ b/controller/misc.go @@ -43,6 +43,7 @@ func GetStatus(c *gin.Context) { defer common.OptionMapRWMutex.RUnlock() passkeySetting := system_setting.GetPasskeySettings() + legalSetting := system_setting.GetLegalSettings() data := gin.H{ "version": common.Version, @@ -108,8 +109,8 @@ func GetStatus(c *gin.Context) { "passkey_user_verification": passkeySetting.UserVerification, "passkey_attachment": passkeySetting.AttachmentPreference, "setup": constant.Setup, - "user_agreement_enabled": common.OptionMap["UserAgreement"] != "", - "privacy_policy_enabled": common.OptionMap["PrivacyPolicy"] != "", + "user_agreement_enabled": legalSetting.UserAgreement != "", + "privacy_policy_enabled": legalSetting.PrivacyPolicy != "", } // 根据启用状态注入可选内容 @@ -154,23 +155,19 @@ func GetAbout(c *gin.Context) { } func GetUserAgreement(c *gin.Context) { - common.OptionMapRWMutex.RLock() - defer common.OptionMapRWMutex.RUnlock() c.JSON(http.StatusOK, gin.H{ "success": true, "message": "", - "data": common.OptionMap["UserAgreement"], + "data": system_setting.GetLegalSettings().UserAgreement, }) return } func GetPrivacyPolicy(c *gin.Context) { - common.OptionMapRWMutex.RLock() - defer common.OptionMapRWMutex.RUnlock() c.JSON(http.StatusOK, gin.H{ "success": true, "message": "", - "data": common.OptionMap["PrivacyPolicy"], + "data": system_setting.GetLegalSettings().PrivacyPolicy, }) return } diff --git a/model/option.go b/model/option.go index 7f341ff33..77525ea25 100644 --- a/model/option.go +++ b/model/option.go @@ -61,8 +61,6 @@ func InitOptionMap() { common.OptionMap["SMTPToken"] = "" common.OptionMap["SMTPSSLEnabled"] = strconv.FormatBool(common.SMTPSSLEnabled) common.OptionMap["Notice"] = "" - common.OptionMap["UserAgreement"] = "" - common.OptionMap["PrivacyPolicy"] = "" common.OptionMap["About"] = "" common.OptionMap["HomePageContent"] = "" common.OptionMap["Footer"] = common.Footer diff --git a/setting/system_setting/legal.go b/setting/system_setting/legal.go new file mode 100644 index 000000000..5758ef71c --- /dev/null +++ b/setting/system_setting/legal.go @@ -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 +} diff --git a/web/src/components/settings/OtherSetting.jsx b/web/src/components/settings/OtherSetting.jsx index 6a159e813..646d21e74 100644 --- a/web/src/components/settings/OtherSetting.jsx +++ b/web/src/components/settings/OtherSetting.jsx @@ -34,12 +34,15 @@ import { useTranslation } from 'react-i18next'; import { StatusContext } from '../../context/Status'; 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 { t } = useTranslation(); let [inputs, setInputs] = useState({ Notice: '', - UserAgreement: '', - PrivacyPolicy: '', + [LEGAL_USER_AGREEMENT_KEY]: '', + [LEGAL_PRIVACY_POLICY_KEY]: '', SystemName: '', Logo: '', Footer: '', @@ -71,8 +74,8 @@ const OtherSetting = () => { const [loadingInput, setLoadingInput] = useState({ Notice: false, - UserAgreement: false, - PrivacyPolicy: false, + [LEGAL_USER_AGREEMENT_KEY]: false, + [LEGAL_PRIVACY_POLICY_KEY]: false, SystemName: false, Logo: false, HomePageContent: false, @@ -103,27 +106,45 @@ const OtherSetting = () => { // 通用设置 - UserAgreement const submitUserAgreement = async () => { try { - setLoadingInput((loadingInput) => ({ ...loadingInput, UserAgreement: true })); - await updateOption('UserAgreement', inputs.UserAgreement); + setLoadingInput((loadingInput) => ({ + ...loadingInput, + [LEGAL_USER_AGREEMENT_KEY]: true, + })); + await updateOption( + LEGAL_USER_AGREEMENT_KEY, + inputs[LEGAL_USER_AGREEMENT_KEY], + ); showSuccess(t('用户协议已更新')); } catch (error) { console.error(t('用户协议更新失败'), error); showError(t('用户协议更新失败')); } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, UserAgreement: false })); + setLoadingInput((loadingInput) => ({ + ...loadingInput, + [LEGAL_USER_AGREEMENT_KEY]: false, + })); } }; // 通用设置 - PrivacyPolicy const submitPrivacyPolicy = async () => { try { - setLoadingInput((loadingInput) => ({ ...loadingInput, PrivacyPolicy: true })); - await updateOption('PrivacyPolicy', inputs.PrivacyPolicy); + setLoadingInput((loadingInput) => ({ + ...loadingInput, + [LEGAL_PRIVACY_POLICY_KEY]: true, + })); + await updateOption( + LEGAL_PRIVACY_POLICY_KEY, + inputs[LEGAL_PRIVACY_POLICY_KEY], + ); showSuccess(t('隐私政策已更新')); } catch (error) { console.error(t('隐私政策更新失败'), error); showError(t('隐私政策更新失败')); } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, PrivacyPolicy: false })); + setLoadingInput((loadingInput) => ({ + ...loadingInput, + [LEGAL_PRIVACY_POLICY_KEY]: false, + })); } }; // 个性化设置 @@ -357,15 +378,18 @@ const OtherSetting = () => { - { placeholder={t( '在此输入隐私政策内容,支持 Markdown & HTML 代码', )} - field={'PrivacyPolicy'} + field={LEGAL_PRIVACY_POLICY_KEY} onChange={handleInputChange} style={{ fontFamily: 'JetBrains Mono, Consolas' }} autosize={{ minRows: 6, maxRows: 12 }} helpText={t('填写隐私政策内容后,用户注册时将被要求勾选已阅读隐私政策')} /> -