Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

头像服务增强:增加一些国内常用的头像服务商 #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/comment-widget/src/avatar/providers/cravatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AvatarProvider from './avatar-provider';

class Cravatar extends AvatarProvider {
override getAvatarSrc(emailHash: string | undefined): string {
return `${this.url}/avatar/${emailHash}`;
}
}

export default new Cravatar('Cravatar', 'https://cravatar.cn');
16 changes: 16 additions & 0 deletions packages/comment-widget/src/avatar/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Gravatar from './gravatar';
import Cravatar from './cravatar';
import Weavatar from "./weavatar";
import AvatarProvider from './avatar-provider';

let avatarProvider: AvatarProvider | undefined;

enum AvatarProviderEnum {
GRAVATAR = 'gravatar',
CRAVATAR = 'cravatar',
WEAVATAR = 'weavatar'
}

export function setAvatarProvider(provider: string, mirrorUrl?: string) {
Expand All @@ -15,6 +19,18 @@ export function setAvatarProvider(provider: string, mirrorUrl?: string) {
}
avatarProvider = Gravatar;
break;
case AvatarProviderEnum.CRAVATAR:
if (mirrorUrl) {
Cravatar.url = mirrorUrl;
}
avatarProvider = Cravatar;
break;
case AvatarProviderEnum.WEAVATAR:
if(mirrorUrl){
Weavatar.url = mirrorUrl;
}
avatarProvider = Weavatar;
break;
default:
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/comment-widget/src/avatar/providers/weavatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AvatarProvider from './avatar-provider';

class Weavatar extends AvatarProvider {
override getAvatarSrc(emailHash: string | undefined): string {
return `${this.url}/avatar/${emailHash}`;
}
}

export default new Weavatar('Weavatar', 'https://weavatar.com');
4 changes: 4 additions & 0 deletions src/main/resources/extensions/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ spec:
options:
- label: "Gravatar"
value: "gravatar"
- label: "Cravatar"
value: "cravatar"
- label: "Weavatar"
value: "weavatar"
value: "gravatar"
- $formkit: text
label: 头像服务镜像地址
Expand Down
Loading