Skip to content

Commit bdd1093

Browse files
committed
feat(mailEncrypt): add email encryption/decryption functions
- refactor email handling logic in handleEmailClick - add new encryptEmail and decryptEmail utility functions - improve error handling for decryption process - simplify the email click handler implementation
1 parent 9973d6b commit bdd1093

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lib/notion/getNotionConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getDateValue, getTextContent } from 'notion-utils'
1010
import { deepClone } from '../utils'
1111
import getAllPageIds from './getAllPageIds'
1212
import { getPage } from './getPostBlocks'
13+
import { encryptEmail } from '@/lib/plugins/mailEncrypt'
1314

1415
/**
1516
* 从Notion中读取Config配置表
@@ -159,7 +160,7 @@ export async function getConfigMapFromConfigPage(allPages) {
159160
// console.log('[Notion配置]', config.key, config.value)
160161
if (config.key === 'CONTACT_EMAIL') {
161162
notionConfig[config.key] =
162-
(config.value && btoa(unescape(encodeURIComponent(config.value)))) || null
163+
(config.value && encryptEmail(config.value)) || null
163164
} else {
164165
notionConfig[config.key] =
165166
parseTextToJson(config.value) || config.value || null

lib/plugins/mailEncrypt.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
export const handleEmailClick = (e, emailIcon, CONTACT_EMAIL) => {
22
if (CONTACT_EMAIL && emailIcon && !emailIcon.current.href) {
33
e.preventDefault()
4-
try {
5-
const email = decodeURIComponent(escape(atob(CONTACT_EMAIL)))
6-
emailIcon.current.href = `mailto:${email}`
7-
emailIcon.current.click()
8-
} catch (error) {
9-
console.error('解密邮箱失败:', error)
10-
}
4+
const email = decryptEmail(CONTACT_EMAIL)
5+
emailIcon.current.href = `mailto:${email}`
6+
emailIcon.current.click()
7+
}
8+
}
9+
10+
export const encryptEmail = email => {
11+
return btoa(unescape(encodeURIComponent(email)))
12+
}
13+
14+
export const decryptEmail = encryptedEmail => {
15+
try {
16+
return decodeURIComponent(escape(atob(encryptedEmail)))
17+
} catch (error) {
18+
console.error('解密邮箱失败:', error)
19+
return encryptedEmail
1120
}
1221
}

0 commit comments

Comments
 (0)