Skip to content

Commit

Permalink
头像服务增强:增加一些国内常用的头像服务商
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjing-xin committed Jul 29, 2024
1 parent 35ab602 commit 07595dc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
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

0 comments on commit 07595dc

Please sign in to comment.