mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
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
This commit is contained in:
@@ -10,6 +10,7 @@ import { getDateValue, getTextContent } from 'notion-utils'
|
||||
import { deepClone } from '../utils'
|
||||
import getAllPageIds from './getAllPageIds'
|
||||
import { getPage } from './getPostBlocks'
|
||||
import { encryptEmail } from '@/lib/plugins/mailEncrypt'
|
||||
|
||||
/**
|
||||
* 从Notion中读取Config配置表
|
||||
@@ -159,7 +160,7 @@ export async function getConfigMapFromConfigPage(allPages) {
|
||||
// console.log('[Notion配置]', config.key, config.value)
|
||||
if (config.key === 'CONTACT_EMAIL') {
|
||||
notionConfig[config.key] =
|
||||
(config.value && btoa(unescape(encodeURIComponent(config.value)))) || null
|
||||
(config.value && encryptEmail(config.value)) || null
|
||||
} else {
|
||||
notionConfig[config.key] =
|
||||
parseTextToJson(config.value) || config.value || null
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
export const handleEmailClick = (e, emailIcon, CONTACT_EMAIL) => {
|
||||
if (CONTACT_EMAIL && emailIcon && !emailIcon.current.href) {
|
||||
e.preventDefault()
|
||||
try {
|
||||
const email = decodeURIComponent(escape(atob(CONTACT_EMAIL)))
|
||||
emailIcon.current.href = `mailto:${email}`
|
||||
emailIcon.current.click()
|
||||
} catch (error) {
|
||||
console.error('解密邮箱失败:', error)
|
||||
}
|
||||
const email = decryptEmail(CONTACT_EMAIL)
|
||||
emailIcon.current.href = `mailto:${email}`
|
||||
emailIcon.current.click()
|
||||
}
|
||||
}
|
||||
|
||||
export const encryptEmail = email => {
|
||||
return btoa(unescape(encodeURIComponent(email)))
|
||||
}
|
||||
|
||||
export const decryptEmail = encryptedEmail => {
|
||||
try {
|
||||
return decodeURIComponent(escape(atob(encryptedEmail)))
|
||||
} catch (error) {
|
||||
console.error('解密邮箱失败:', error)
|
||||
return encryptedEmail
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user