Skip to content

Commit

Permalink
[FEATURE] Uniform avatar configure by AVATAR_PROXY (#555)
Browse files Browse the repository at this point in the history
* feat: export avatar field for comment

* feat: export avatar field for user

* feat: use avatar field at first for comment

* doc: remove avatar client config desc and add AVATAR_PROXY desc

* feat: change gravatar to libravatar

* style: fix linter

Co-authored-by: Mr.Hope <zhangbowang1998@gmail.com>
  • Loading branch information
lizheming and Mister-Hope committed Sep 21, 2021
1 parent e4225d3 commit ff0958e
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 138 deletions.
4 changes: 4 additions & 0 deletions docs/en/guide/client/avatar.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Avatar Configuration

::: danger Deprecated
The configure is deprecated, because gravatar avatar setting migrated to server configure `AVATAR_PROXY`.
:::

Waline currently uses [Libravatar][1] as the comment list avatar.

Libravatar is a free, open-source avatar provider features federated hosting and Gravatar-compatible APIs.
Expand Down
92 changes: 55 additions & 37 deletions docs/en/reference/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,6 @@ Login mode status, optional values:
- `'disable'`: Login is disabled, users should fill in infomation to comment
- `'force'`: Forced login, users must login to comment

## avatar

- Type: `string`
- Default: `'mp'`
- Required: No

[Gravatar](http://gravatar.com/) type.

Optional value:

- `''` (Empty string)
- `'mp'`
- `'identicon'`
- `'monsterid'`
- `'wavatar'`
- `'retro'`
- `'robohash'`
- `'hide'`

See the [Avatar setting](../guide/client/avatar.md) for more details.

## wordLimit

- Type: `number | [number, number]`
Expand All @@ -164,22 +143,6 @@ Comment word s limit. When a single number is filled in, it 's the maximum numbe

number of comments per page.

## avatarCDN

- Type: `string`
- Default: `https://seccdn.libravatar.org/avatar/`
- Required: No

Avatar provider baseURL. Supports Gravatar-compatible APIs.

## avatarForce

- Type: `boolean`
- Default: `false`
- Required: No

Whether **force** pulling the latest avatar each time.

## uploadImage

- Type: `Function | false`
Expand Down Expand Up @@ -299,10 +262,65 @@ Please use `login` instead.

Whether to allow login comments. Both supported by default, set to `true` means only support anonymous comments, `false` means only support login comments.

## avatarCDN

::: warning Obsolete

The configure is deprecated, because gravatar avatar setting migrated to server configure `AVATAR_PROXY`.

:::

- Type: `string`
- Default: `https://seccdn.libravatar.org/avatar/`
- Required: No

Avatar provider baseURL. Supports Gravatar-compatible APIs.

### copyRight

::: danger Deprecated

Please use `copyright` instead.

:::

## avatar

::: danger Deprecated

The configure is deprecated, because gravatar avatar setting migrated to server configure `AVATAR_PROXY`.

:::

- Type: `string`
- Default: `'mp'`
- Required: No

[Gravatar](http://gravatar.com/) type.

Optional value:

- `''` (Empty string)
- `'mp'`
- `'identicon'`
- `'monsterid'`
- `'wavatar'`
- `'retro'`
- `'robohash'`
- `'hide'`

See the [Avatar setting](../guide/client/avatar.md) for more details.

## avatarForce

::: danger Deprecated

The configure is deprecated, because gravatar avatar setting migrated to server configure `AVATAR_PROXY`.

:::

- Type: `boolean`
- Default: `false`
- Required: No

Whether **force** pulling the latest avatar each time.
26 changes: 14 additions & 12 deletions docs/en/reference/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ Vercel needs to be set in <kbd>Settings</kbd> - <kbd>Environment Variables</kbd>

### Basic

| Environment Variables | Required | Description |
| --------------------- | -------- | --------------------------------------------------------------------------------- |
| `LEAN_ID` || LeanCloud Application ID |
| `LEAN_KEY` || LeanCloud Application Key |
| `LEAN_MASTER_KEY` || LeanCloud Application Master Key |
| `LEAN_SERVER` || LeanCloud server address if you're leancloud china user |
| `SITE_NAME` | | site name |
| `SITE_URL` | | site url |
| `SECURE_DOMAINS` | | Secure Domains config. Supports multiple domain with Comma separated |
| `DISABLE_USERAGENT` | | wether hide the user agent of commentor. Default value is `false` |
| `AKISMET_KEY` | | Akismet antispam service key, default is open, set `false` if you wanna close it. |
| `COMMENT_AUDIT` | | Comment audit switcher. We recommend to tip on the placeholder text if it's true. |
| Environment Variables | Required | Description |
| --------------------- | -------- | -------------------------------------------------------------------------------------------------------- |
| `LEAN_ID` || LeanCloud Application ID |
| `LEAN_KEY` || LeanCloud Application Key |
| `LEAN_MASTER_KEY` || LeanCloud Application Master Key |
| `LEAN_SERVER` || LeanCloud server address if you're leancloud china user |
| `SITE_NAME` | | site name |
| `SITE_URL` | | site url |
| `SECURE_DOMAINS` | | Secure Domains config. Supports multiple domain with Comma separated |
| `DISABLE_USERAGENT` | | wether hide the user agent of commentor. Default value is `false` |
| `AKISMET_KEY` | | Akismet antispam service key, default is open, set `false` if you wanna close it. |
| `COMMENT_AUDIT` | | Comment audit switcher. We recommend to tip on the placeholder text if it's true. |
| `LOGIN` | | User need login before comment when `LOGIN=force` |
| `AVATAR_PROXY` | | Avatar proxy service url, default is `https://avatar.75cdn.workers.dev`. You can set `false` to close it |

### Markdown

Expand Down
4 changes: 4 additions & 0 deletions docs/guide/client/avatar.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 头像配置

::: danger 已废弃
Gravatar 头像配置统一走服务端的 AVATAR_PROXY 配置,该配置已废弃
:::

Waline 目前使用 [Libravatar][1] 获取评论列表头像。

Libravatar 是自由、开放原始码的头像服务,支持联邦托管并与 [Gravatar][2] 兼容。
Expand Down
96 changes: 57 additions & 39 deletions docs/reference/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,6 @@ Waline 的服务端地址。
- `'disable'`: 禁用登录,用户只能填写信息评论
- `'force'`: 强制登录,用户必须注册并登录才可发布评论

## avatar

- 类型: `string`
- 默认值: `mp`
- 必填: 否

[Gravatar](http://cn.gravatar.com/) 头像展示方式。

可选值:

- `''`
- `'mp'`
- `'identicon'`
- `'monsterid'`
- `'wavatar'`
- `'retro'`
- `'robohash'`
- `'hide'`

更多信息,请查看 [头像配置](../guide/client/avatar.md)

## wordLimit

- 类型: `number | [number, number]`
Expand All @@ -164,24 +143,6 @@ Waline 的服务端地址。

评论列表分页,每页条数。

## avatarCDN

- 类型: `string`
- 默认值: `https://seccdn.libravatar.org/avatar/`
- 必填: 否

设置头像 CDN 地址。可使用任何与 [Gravatar](http://cn.gravatar.com/) API 兼容的服务。

## avatarForce

- 类型: `boolean`
- 默认值: `false`
- 必填: 否

每次访问是否**强制**拉取最新的*评论列表头像*

> 不推荐设置为 `true`,目前的*评论列表头像*会自动带上 `Waline` 的版本号
## uploadImage

- 类型: `Function | false`
Expand Down Expand Up @@ -301,10 +262,67 @@ Waline 的服务端地址。

是否允许登录评论。默认情况是两者都支持,设置为 `true` 表示仅支持匿名评论,`false` 表示仅支持登录评论。

## avatarCDN

::: warning 已过时

Gravatar 头像配置统一走服务端的 AVATAR_PROXY 配置,该配置已废弃

:::

- 类型: `string`
- 默认值: `https://seccdn.libravatar.org/avatar/`
- 必填: 否

设置头像 CDN 地址。可使用任何与 [Gravatar](http://cn.gravatar.com/) API 兼容的服务。

### copyRight

::: danger 已废弃

请使用 `copyright`

:::

## avatar

::: danger 已废弃

Gravatar 头像配置统一走服务端的 AVATAR_PROXY 配置,该配置已废弃

:::

- 类型: `string`
- 默认值: `mp`
- 必填: 否

[Gravatar](http://cn.gravatar.com/) 头像展示方式。

可选值:

- `''`
- `'mp'`
- `'identicon'`
- `'monsterid'`
- `'wavatar'`
- `'retro'`
- `'robohash'`
- `'hide'`

更多信息,请查看 [头像配置](../guide/client/avatar.md)

## avatarForce

::: danger 已废弃

Gravatar 头像配置使用服务端的 AVATAR_PROXY,该配置已废弃

:::

- 类型: `boolean`
- 默认值: `false`
- 必填: 否

每次访问是否**强制**拉取最新的*评论列表头像*

> 不推荐设置为 `true`,目前的*评论列表头像*会自动带上 `Waline` 的版本号
29 changes: 15 additions & 14 deletions docs/reference/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ Vercel 需要在 <kbd>Settings</kbd> - <kbd>Environment Variables</kbd> 中进

### 主要配置

| 环境变量名称 | 必填 | 备注 |
| ------------------- | ---- | ------------------------------------------------------------------- |
| `LEAN_ID` || LeanCloud 应用的 App ID |
| `LEAN_KEY` || LeanCloud 应用的 App Key |
| `LEAN_MASTER_KEY` || LeanCloud 应用的 Master Key 用于后台修改数据 |
| `LEAN_SERVER` || LeanCloud 服务地址,国内版用户需要配置此项 |
| `SITE_NAME` | | 博客名称 |
| `SITE_URL` | | 博客地址 |
| `IPQPS` | | 基于 IP 的评论发布频率限制,单位为秒。默认为 60 秒,设置为 0 不限制 |
| `SECURE_DOMAINS` | | 安全域名配置,支持逗号分隔配置多个域名 |
| `DISABLE_USERAGENT` | | 是否隐藏评论者的 UA,默认为否 |
| `AKISMET_KEY` | | Akismet 反垃圾评论服务 Key(默认开启,不用请设置为 false) |
| `COMMENT_AUDIT` | | 评论发布审核开关,配置后建议在 Placehoder 上提供文案提示 |
| `LOGIN` | | 当设置为 `LOGIN=force` 时会要求登录才能评论 |
| 环境变量名称 | 必填 | 备注 |
| ------------------- | ---- | -------------------------------------------------------------------------------- |
| `LEAN_ID` || LeanCloud 应用的 App ID |
| `LEAN_KEY` || LeanCloud 应用的 App Key |
| `LEAN_MASTER_KEY` || LeanCloud 应用的 Master Key 用于后台修改数据 |
| `LEAN_SERVER` || LeanCloud 服务地址,国内版用户需要配置此项 |
| `SITE_NAME` | | 博客名称 |
| `SITE_URL` | | 博客地址 |
| `IPQPS` | | 基于 IP 的评论发布频率限制,单位为秒。默认为 60 秒,设置为 0 不限制 |
| `SECURE_DOMAINS` | | 安全域名配置,支持逗号分隔配置多个域名 |
| `DISABLE_USERAGENT` | | 是否隐藏评论者的 UA,默认为否 |
| `AKISMET_KEY` | | Akismet 反垃圾评论服务 Key(默认开启,不用请设置为 false) |
| `COMMENT_AUDIT` | | 评论发布审核开关,配置后建议在 Placehoder 上提供文案提示 |
| `LOGIN` | | 当设置为 `LOGIN=force` 时会要求登录才能评论 |
| `AVATAR_PROXY` | | 头像的代理地址,默认为 `https://avatar.75cdn.workers.dev`,设置 `false` 关闭代理 |

### Markdown

Expand Down
3 changes: 2 additions & 1 deletion packages/admin/src/pages/manage-comments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export default function () {
objectId,
nick,
mail,
avatar,
link,
comment,
ip,
Expand Down Expand Up @@ -526,7 +527,7 @@ export default function () {
<div className="comment-avatar">
<img
className="avatar"
src={buildAvatar(mail)}
src={buildAvatar(mail, avatar)}
alt={nick}
width="40"
height="40"
Expand Down
6 changes: 5 additions & 1 deletion packages/admin/src/pages/manage-comments/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import md5 from 'md5';

export function buildAvatar(email = '') {
export function buildAvatar(email = '', avatar = '') {
if (avatar) {
return avatar;
}

if (typeof email !== 'string') {
email = '';
}
Expand Down
16 changes: 9 additions & 7 deletions packages/server/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ if (think.env === 'cloudbase' && storage === 'sqlite') {

const forbiddenWords = FORBIDDEN_WORDS ? FORBIDDEN_WORDS.split(/\s*,\s*/) : [];

const isFalse = (content) => content && content.toLowerCase() === 'false';
const isFalse = (content) =>
content && ['0', 'false'].includes(content.toLowerCase());

const markdown = {
config: JSON.parse(MARKDOWN_CONFIG),
Expand All @@ -81,20 +82,21 @@ const markdown = {

if (isFalse(MARKDOWN_HIGHLIGHT)) markdown.config.highlight = false;

let avatarProxy = 'https://avatar.75cdn.workers.dev/';
if (AVATAR_PROXY) {
avatarProxy = !isFalse(AVATAR_PROXY) ? AVATAR_PROXY : '';
}

module.exports = {
workers: 1,
storage,
jwtKey,
forbiddenWords,
disallowIPList: [],
secureDomains: SECURE_DOMAINS ? SECURE_DOMAINS.split(/\s*,\s*/) : undefined,
disableUserAgent:
DISABLE_USERAGENT &&
!['0', 'false'].includes(DISABLE_USERAGENT.toLowerCase()),
avatarProxy: AVATAR_PROXY || 'https://avatar.75cdn.workers.dev/',

disableUserAgent: !isFalse(DISABLE_USERAGENT),
avatarProxy,
markdown,

mailSubject: MAIL_SUBJECT,
mailTemplate: MAIL_TEMPLATE,
mailSubjectAdmin: MAIL_SUBJECT_ADMIN,
Expand Down

0 comments on commit ff0958e

Please sign in to comment.