Skip to content

Commit

Permalink
fix: 邮箱打码
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Feb 21, 2024
1 parent c46c8fe commit 76caf5d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
6 changes: 4 additions & 2 deletions apps/vocal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import plugin from '../../../lib/plugins/plugin.js'
import { SunoClient } from '../client/SunoClient.js'
import { Config } from '../utils/config.js'
import { downloadFile } from '../utils/common.js'
import { downloadFile, maskEmail } from '../utils/common.js'
import common from '../../../lib/common/common.js'

export class Vocal extends plugin {
Expand Down Expand Up @@ -59,7 +59,9 @@ export class Vocal extends plugin {
let client = new SunoClient({ sessToken: sess, clientToken })
let { credit, email } = await client.queryCredit()
logger.info({ credit, email })
msg += `用户${email}余额:${credit}\n`
msg += `用户: ${maskEmail(email)} 余额:${credit}\n`
msg += '-------------------\n'
msg += 'Notice:每首歌消耗5credit,每次生成2首歌'
}
await e.reply(msg)
return true
Expand Down
51 changes: 50 additions & 1 deletion utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { translate } from './translate.js'
import uploadRecord from './uploadRecord.js'
import Version from './version.js'
import fetch, { FormData, fileFromSync } from 'node-fetch'
import https from "https";
import https from 'https'
let pdfjsLib
try {
pdfjsLib = (await import('pdfjs-dist')).default
Expand Down Expand Up @@ -1261,3 +1261,52 @@ export async function extractContentFromFile (fileMsgElem, e) {
return {}
}
}

/**
* generated by ai
* @param email
* @returns {string}
*/
export function maskEmail (email) {
// 使用正则表达式匹配电子邮件地址的用户名和域名部分
const regex = /^([^@]+)@([^@]+)$/
const match = email.match(regex)

if (!match) {
throw new Error('Invalid email format')
}

// 获取用户名和域名
const username = match[1]
const domain = match[2]

// 对用户名部分进行部分打码
const maskedUsername = maskString(username)

// 对域名部分进行部分打码
const maskedDomain = maskString(domain)

// 构造新的电子邮件地址
const maskedEmail = maskedUsername + '@' + maskedDomain

return maskedEmail
}

/**
* generated by ai
* @param str
* @returns {*|string}
*/
function maskString (str) {
// 如果字符串长度小于等于2,直接返回原字符串
if (str.length <= 2) {
return str
}

// 取字符串的前三个字符和后三个字符,中间使用*代替
const firstThreeChars = str.substring(0, 3)
const lastThreeChars = str.substring(str.length - 3)
const maskedChars = '*'.repeat(str.length - 6)

return firstThreeChars + maskedChars + lastThreeChars
}

0 comments on commit 76caf5d

Please sign in to comment.