@yoooloo42/beat 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/libs/Email.js +4 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoooloo42/beat",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "homepage": "https://github.com/13993193075/beat#readme",
19
19
  "dependencies": {
20
+ "@yoooloo42/bean": "^1.0.9",
20
21
  "nodemailer": "^7.0.10"
21
22
  },
22
23
  "exports": {
package/src/libs/Email.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import nodemailer from 'nodemailer';
2
+ import random from '@yoooloo42/bean/utils/random';
2
3
 
3
4
  /**
4
5
  * Node.js 项目中发送电子邮件的函数
@@ -60,22 +61,6 @@ async function sendEmail(to, subject, htmlContent, textContent = '') {
60
61
  }
61
62
  }
62
63
 
63
- /**
64
- * 生成指定长度的随机数字验证码
65
- * @param {number} length - 验证码长度 (默认 6 位)
66
- * @returns {string} - 随机数字字符串
67
- */
68
- function vercode(length = 6) {
69
- let code = '';
70
- // 确保第一位不是 0,除非长度只有一位
71
- code += Math.floor(Math.random() * 9) + 1;
72
-
73
- for (let i = 1; i < length; i++) {
74
- code += Math.floor(Math.random() * 10);
75
- }
76
- return code;
77
- }
78
-
79
64
  /**
80
65
  * 发送包含验证码的邮件
81
66
  * * @param {string} recipientEmail - 收件人邮箱地址
@@ -83,10 +68,9 @@ function vercode(length = 6) {
83
68
  * @param {number} [expirationMinutes=5] - 验证码有效时间(分钟)
84
69
  * @returns {Promise<{success: boolean, code?: string, error?: string}>} - 包含发送结果和生成的验证码
85
70
  */
86
- async function sendEmailVercode(recipientEmail, codeLength = 6, expirationMinutes = 5) {
87
-
71
+ async function sendVercode(recipientEmail, codeLength = 6, expirationMinutes = 5) {
88
72
  // 1. 生成验证码
89
- const verificationCode = vercode(codeLength);
73
+ const verificationCode = random.vercode6(codeLength);
90
74
 
91
75
  // 2. 构造邮件内容
92
76
  const subject = `您的验证码:${verificationCode},请注意妥善保管,切勿泄露`;
@@ -122,7 +106,6 @@ async function sendEmailVercode(recipientEmail, codeLength = 6, expirationMinute
122
106
 
123
107
  const beat = {
124
108
  sendEmail,
125
- vercode,
126
- sendEmailVercode
109
+ sendVercode
127
110
  }
128
111
  export default beat