Skip to content

Commit

Permalink
feat(server): add SHA256 filter for GRAVATAR_STR (#2488)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuNatsu committed May 11, 2024
1 parent 771da32 commit 4e28685
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/server/src/service/avatar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const crypto = require('crypto');

const nunjucks = require('nunjucks');
const helper = require('think-helper');

Expand All @@ -6,6 +8,9 @@ const { GRAVATAR_STR } = process.env;
const env = new nunjucks.Environment();

env.addFilter('md5', (str) => helper.md5(str));
env.addFilter('sha256', (str) =>
crypto.createHash('sha256').update(str).digest('hex'),
);

const DEFAULT_GRAVATAR_STR = `{%- set numExp = r/^[0-9]+$/g -%}
{%- set qqMailExp = r/^[0-9]+@qq.com$/ig -%}
Expand Down

0 comments on commit 4e28685

Please sign in to comment.