fix: support gravatar mirror sites

This commit is contained in:
shuai 2023-05-15 15:52:08 +08:00
parent 2076dcd0e5
commit 5b98eff4bc
7 changed files with 34 additions and 15 deletions

View File

@ -828,7 +828,7 @@ ui:
avatar:
label: Profile Image
gravatar: Gravatar
gravatar_text: You can change image on <1>gravatar.com</1>
gravatar_text: You can change image on
custom: Custom
btn_refresh: Refresh
custom_text: You can upload your image.
@ -1556,6 +1556,9 @@ ui:
avatar:
label: Default Avatar
text: For users without a custom avatar of their own.
gravatar_base_url:
label: Gravatar Base URL
text: URL of the Gravatar providers API base. Ignored when empty.
profile_editable:
title: Profile Editable
allow_update_display_name:

View File

@ -333,6 +333,7 @@ export interface AdminSettingsUsers {
allow_update_username: boolean;
allow_update_website: boolean;
default_avatar: string;
gravatar_base_url: string;
}
export interface SiteSettings {
@ -568,8 +569,3 @@ export interface UserOauthConnectorItem extends OauthConnectorItem {
binding: boolean;
external_id: string;
}
export interface QuestionOperationReq {
id: string;
operation: 'pin' | 'unpin' | 'hide' | 'show';
}

View File

@ -31,6 +31,11 @@ const Index: FC = () => {
enumNames: SYSTEM_AVATAR_OPTIONS?.map((v) => v.label),
default: 'system',
},
gravatar_base_url: {
type: 'string',
title: t('gravatar_base_url.label'),
description: t('gravatar_base_url.text'),
},
profile_editable: {
type: 'string',
title: t('profile_editable.title'),
@ -68,6 +73,9 @@ const Index: FC = () => {
default_avatar: {
'ui:widget': 'select',
},
gravatar_base_url: {
'ui:widget': 'input',
},
profile_editable: {
'ui:widget': 'legend',
},
@ -127,6 +135,7 @@ const Index: FC = () => {
allow_update_username: formData.allow_update_username.value,
allow_update_website: formData.allow_update_website.value,
default_avatar: formData.default_avatar.value,
gravatar_base_url: formData.gravatar_base_url.value,
};
putUsersSetting(reqParams)
.then(() => {
@ -155,6 +164,9 @@ const Index: FC = () => {
if (k === 'default_avatar' && !v) {
v = 'system';
}
if (k === 'gravatar_base_url' && !v) {
v = 'https://www.gravatar.com/avatar/';
}
formMeta[k] = { ...formData[k], value: v };
});
setFormData({ ...formData, ...formMeta });

View File

@ -81,6 +81,7 @@ const Index = () => {
useEffect(() => {
return () => {
console.log('clear data');
setFormData({
displayName: {
value: '',

View File

@ -355,15 +355,20 @@ const Index: React.FC = () => {
className="me-3 rounded"
/>
<Form.Text className="text-muted mt-1">
<Trans i18nKey="settings.profile.avatar.gravatar_text">
You can change image on
<span>{t('avatar.gravatar_text')}</span>
<a
href="https://gravatar.com"
href={
usersSetting.gravatar_base_url.includes('gravatar.cn')
? 'https://gravatar.cn'
: 'https://gravatar.com'
}
className="ms-1"
target="_blank"
rel="noreferrer">
gravatar.com
{usersSetting.gravatar_base_url.includes('gravatar.cn')
? 'gravatar.cn'
: 'gravatar.com'}
</a>
</Trans>
</Form.Text>
</Stack>
)}

View File

@ -11,6 +11,7 @@ export interface AdminSettingsUsers {
allow_update_username: boolean;
allow_update_website: boolean;
default_avatar: string;
gravatar_base_url: string;
}
interface PrivilegeLevel {

View File

@ -21,6 +21,7 @@ const defaultUsersConf: AdminSettingsUsers = {
allow_update_username: false,
allow_update_website: false,
default_avatar: 'system',
gravatar_base_url: 'https://www.gravatar.com/avatar/',
};
const siteInfo = create<SiteInfoType>((set) => ({