From 76caf5d04083c3c01318c35f360da86a9bf0a079 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Wed, 21 Feb 2024 14:50:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=82=AE=E7=AE=B1=E6=89=93=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/vocal.js | 6 ++++-- utils/common.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/apps/vocal.js b/apps/vocal.js index 03d0062..be8d969 100644 --- a/apps/vocal.js +++ b/apps/vocal.js @@ -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 { @@ -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 diff --git a/utils/common.js b/utils/common.js index 3a00052..5adccbc 100644 --- a/utils/common.js +++ b/utils/common.js @@ -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 @@ -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 +}