Compare commits

...

10 Commits

Author SHA1 Message Date
Luk
d27531ea00 u 2025-03-15 14:14:24 +08:00
Luk
292e138732 u 2024-11-25 22:01:38 +08:00
luk
b4408ce9f9 u 2024-11-03 14:09:16 +08:00
Luk
dbd0e0b13f ignore *nogit* and *nosf* 2024-09-22 15:51:35 +08:00
luk
7b200e283a if smtp or sms config is empty, return immediately 2024-08-03 14:22:03 +08:00
Luk
5fd32c86b3 improve gitignore and seafile-ignore 2024-04-24 14:18:13 +08:00
Luk
15b87bbd7c u 2024-02-05 11:37:07 +08:00
Luk
5104ce87ee console.log({_at, ...}) 2024-02-05 09:52:18 +08:00
Luk
159f90f44a add some prompts when sendMail returns 2024-01-29 20:43:46 +08:00
Luk
2a4f962e1c updated .gitignore and seafile-ignore.txt using npm/sysconfig/*-ignore-find2merge.sh 2024-01-28 12:18:03 +08:00
3 changed files with 177 additions and 105 deletions

33
.gitignore vendored
View File

@@ -1,16 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# how to include another gitignore?
# https://stackoverflow.com/questions/7005142/can-i-include-other-gitignore-file-in-a-gitignore-file-like-include-in-c-li
# https://github.com/github/gitignore
# https://github.com/SlideWave/gitignore-include?tab=readme-ov-file#examples
# https://gitignore.io
### 目录 ################################################################# ### .gitignore.global.txt ###
# Self defined pattern to ignore
?*.gitignore
?*.gitignore/
?*.gitignore.*
?*.gitignore.*/
*.gitomit
*.gitomit.*
*.gitomit/
*.gitomit.*/
*.nogit
*.nogit.*
*.nogit/
*.nogit.*/
# 保留
!.gitignore
!.gitignore.*
!.gitkeep
# 通用 # 通用
.svn/ .svn/
.deploy_git/ .deploy_git/
.idea/ .idea/
.sass-cache/ .sass-cache/
.wrangler
/test/unit/coverage/ /test/unit/coverage/
/test/e2e/reports/ /test/e2e/reports/
node_modules/ node_modules/
*.aab
*.apk *.apk
*.ipa
*.min.js *.min.js
*.min.css *.min.css
*.min.html *.min.html
@@ -70,7 +96,6 @@ _desktop.ini
/db.json /db.json
# wo # wo
*.gitignore.*
# 服务端 # 服务端
/_archive/* /_archive/*
/_datastore/* /_datastore/*
@@ -84,5 +109,5 @@ _desktop.ini
package-lock.json package-lock.json
pages4loader.json5 pages4loader.json5
# 保留 ### .gitignore.local.txt ###
!.gitkeep

View File

@@ -13,21 +13,38 @@ module.exports = {
// 或者如果smtp参数已经确定就可以直接定义 sendMail: Bluebird.promisify(Smtp.sendMail).bind(Smtp) // 或者如果smtp参数已经确定就可以直接定义 sendMail: Bluebird.promisify(Smtp.sendMail).bind(Smtp)
async sendMail (messageObject, smtp = my.envar?.SMTP || wo?.envar?.SMTP) { async sendMail (messageObject, smtp = my.envar?.SMTP || wo?.envar?.SMTP) {
if (!smtp?.host) {
globalThis.wo?.ccerror?.({ _state: 'SMTP_CONFIG_MALFORMED', smtp })
return { _state: 'SMTP_CONFIG_MALFORMED', smtp }
}
// messageObject: { from, to, cc, bcc, subject, text, html, sender, replyTo, inReplyTo } // messageObject: { from, to, cc, bcc, subject, text, html, sender, replyTo, inReplyTo }
sender.smtpTransporter = sender.smtpTransporter || NodeMailer.createTransport(smtp) sender.smtpTransporter = sender.smtpTransporter || NodeMailer.createTransport(smtp)
return await sender.smtpTransporter return await sender.smtpTransporter
.sendMail(messageObject) .sendMail(messageObject)
.then((result) => { .then((result) => {
if (result.messageId && result.response === '250 Ok') { /*
console.log(result) {
return { _state: 'MSG_SENT_SUCCESS' } accepted: [ 'anolaxy+1@outlook.com' ],
rejected: [],
envelopeTime: 159,
messageTime: 160,
messageSize: 1055,
response: '250 Ok',
envelope: { from: 'hi@babely.cc', to: [ 'anolaxy+1@outlook.com' ] },
messageId: '<f78681c8-f5d7-4149-4abf-4b940497535f@babely.cc>'
} }
console.log(result) */
if (result.messageId && result.response === '250 Ok') {
globalThis.wo?.cclog?.({ _state: 'MSG_SENT_SUCCESS', subject: messageObject.subject, ...result.envelope })
return { _state: 'MSG_SENT_SUCCESS' }
} else {
globalThis.wo?.cclog?.({ _state: 'MSG_SEND_FAIL', subject: messageObject.subject, ...result })
return { _state: 'MSG_SEND_FAIL' } return { _state: 'MSG_SEND_FAIL' }
}
}) })
.catch((err) => { .catch((error) => {
console.log(err) globalThis.wo?.ccerror?.({ _state: 'MSG_SEND_ERROR', subject: messageObject.subject, error })
return { _state: 'SMS_SEND_ERROR' } return { _state: 'MSG_SEND_ERROR' }
}) })
}, },
@@ -41,21 +58,28 @@ module.exports = {
signName, // for 'ALIYUN', 'TENCENT' signName, // for 'ALIYUN', 'TENCENT'
appid, // for 'UNICLOUD', 'TENCENT' appid, // for 'UNICLOUD', 'TENCENT'
} = {}) { } = {}) {
let result
if (/^\+\d+-\d+$/.test(phone)) { if (/^\+\d+-\d+$/.test(phone)) {
if (config.vendor === 'DXTON') { if (!config?.vendor) {
return await this.sendSmsDxton({ phone, config, msg }) result = { _state: 'SMS_CONFIG_MALFORMED', phone, config }
} else if (config.vendor === 'DXTON') {
result = await this.sendSmsDxton({ phone, config, msg })
} else if (config.vendor === 'ALIYUN') { } else if (config.vendor === 'ALIYUN') {
return await this.sendSmsAliyun({ phone, config, msgParam, msgTemplate, signName }) result = await this.sendSmsAliyun({ phone, config, msgParam, msgTemplate, signName })
} else if (config.vendor === 'UNICLOUD') {
return await this.sendSmsUnicloud({ phone, config, msgParam, msgTemplate, appid })
} else if (config.vendor === 'TENCENT') { } else if (config.vendor === 'TENCENT') {
return await this.sendSmsTencent({ phone, config, msgParam, msgTemplate, appid, signName }) result = await this.sendSmsTencent({ phone, config, msgParam, msgTemplate, appid, signName })
} else if (config.vendor === 'UNICLOUD') {
result = await this.sendSmsUnicloud({ phone, config, msgParam, msgTemplate, appid })
} else { } else {
return { _state: 'SMS_UNKNOWN_VENDOR', error: { unknownVendor: config.vendor } } result = { _state: 'SMS_UNKNOWN_VENDOR', error: { unknownVendor: config.vendor } }
} }
} else { } else {
return { _state: 'SMS_INVALID_PHONE', error: {} } result = { _state: 'SMS_INVALID_PHONE', error: {} }
} }
globalThis.wo?.cclog?.({ phone, signName, msgParam, msgTemplate, ...result })
return result
}, },
/* 使用 dxton.com 的短信接口 http://www.dxton.com/help_detail/38.html /* 使用 dxton.com 的短信接口 http://www.dxton.com/help_detail/38.html
@@ -92,7 +116,7 @@ module.exports = {
}) })
}) })
.on('error', (error) => { .on('error', (error) => {
reject({ _state: 'SMS_SEND_ERROR', error }) reject({ _state: 'MSG_SEND_ERROR', error })
}) })
}) })
}, },
@@ -120,7 +144,34 @@ module.exports = {
} }
}, },
function (error) { function (error) {
return { _state: 'SMS_SEND_ERROR', error } return { _state: 'MSG_SEND_ERROR', error }
}
)
},
async sendSmsTencent ({ phone, config, msgTemplate, msgParam, appid, signName } = {}) {
sender.smsClientTencent = sender.smsClientTencent || new (require('tencentcloud-sdk-nodejs').sms.v20210111.Client)(config) // https://cloud.tencent.com/document/product/382/43197
return await sender.smsClientTencent
.SendSms({
// API: https://cloud.tencent.com/document/product/382/55981
PhoneNumberSet: [phone.replace('-', '')],
SmsSdkAppId: appid || config.appid,
SignName: typeof signName !== 'undefined' ? signName : config.signName, // 腾讯云的国际短信可以没有签名,因此允许传入参数 signName:'' 来覆盖默认的 config.signName
TemplateId: msgTemplate || config.msgTemplate,
TemplateParamSet: Object.values(msgParam),
})
.then(
function ({ SendStatusSet, RequestId } = {}) {
let { SerialNo, PhoneNumber, Fee, Code, Message, IsoCode } = SendStatusSet[0]
if (Code === 'Ok') {
return { _state: 'MSG_SENT_SUCCESS' }
} else {
return { _state: 'MSG_SEND_FAIL', error: { SendStatusSet, RequestId } }
}
},
function (error) {
return { _state: 'MSG_SEND_ERROR', error }
} }
) )
}, },
@@ -136,40 +187,18 @@ module.exports = {
data: msgParam, // 模版中的变量的值,例如 { passcode: '234345', purpose: '注册' } data: msgParam, // 模版中的变量的值,例如 { passcode: '234345', purpose: '注册' }
}) })
return { _state: 'MSG_SENT_SUCCESS', result } // 调用成功,请注意这时不代表发送成功。// { code:0, errCode:0, success:true } 错误码参见 https://uniapp.dcloud.net.cn/uniCloud/send-sms.html if (result?.errorCode === 0) {
return { _state: 'MSG_SENT_SUCCESS', result } // { code:0, errCode:0, success:true }
} else {
// 错误码参见 https://doc.dcloud.net.cn/uniCloud/sms/dev.html
return { _state: 'MSG_SEND_FAIL', result }
}
} catch (error) { } catch (error) {
// 调用失败 例如 {"code":undefined,"msg":"短信发送失败:账户余额不足"} // 调用失败 例如 {"code":undefined,"msg":"短信发送失败:账户余额不足"}
return { return {
_state: 'MSG_SEND_FAIL', _state: 'MSG_SEND_ERROR',
error, // { errCode, errMsg } error, // { errCode, errMsg }
} }
} }
}, },
async sendSmsTencent ({ phone, config, msgTemplate, msgParam, appid, signName } = {}) {
sender.smsClientTencent = sender.smsClientTencent || new (require('tencentcloud-sdk-nodejs').sms.v20210111.Client)(config) // https://cloud.tencent.com/document/product/382/43197
return await sender.smsClientTencent
.SendSms({
// API: https://cloud.tencent.com/document/product/382/55981
PhoneNumberSet: [phone.replace('-', '')],
SmsSdkAppId: appid || config.appid,
SignName: signName || config.signName,
TemplateId: msgTemplate || config.msgTemplate,
TemplateParamSet: Object.values(msgParam),
})
.then(
function ({ SendStatusSet, RequestId } = {}) {
let { SerialNo, PhoneNumber, Fee, Code, Message, IsoCode } = SendStatusSet[0]
if (Code === 'Ok') {
return { _state: 'MSG_SENT_SUCCESS' }
} else {
return { _state: 'MSG_SEND_FAIL', error: { SendStatusSet, RequestId } }
}
},
function (error) {
return { _state: 'SMS_SEND_ERROR', error }
}
)
},
} }

View File

@@ -6,11 +6,21 @@
# 文件在服务器端的后续更改会被同步到客户端,如果客户端也同时修改了这些文件,系统会生成冲突文件。 # 文件在服务器端的后续更改会被同步到客户端,如果客户端也同时修改了这些文件,系统会生成冲突文件。
# seafile-ignore.txt 只能忽略还没有被同步的文件。对于已经被同步的文件,如果后来把它添加到 seafile-ignore.txt 中,系统只会忽略后续更改,已经上传的版本不会受影响。 # seafile-ignore.txt 只能忽略还没有被同步的文件。对于已经被同步的文件,如果后来把它添加到 seafile-ignore.txt 中,系统只会忽略后续更改,已经上传的版本不会受影响。
### seafile-ignore.global.txt ###
# 自定义的后缀名,凡有 sfignore 后缀的都不进行同步 # 自定义的后缀名,凡有 sfignore 后缀的都不进行同步
*.sfignore *.sfignore
*.sfignore.*
*.sfignore/ *.sfignore/
*.sfignore.*
*.sfignore.*/ *.sfignore.*/
*.sfomit
*.sfomit.*
*.sfomit/
*.sfomit.*/
*.nosf
*.nosf.*
*.nosf/
*.nosf.*/
.DS_Store .DS_Store
*/.DS_Store */.DS_Store
@@ -41,14 +51,22 @@ package-lock.json
pages4loader.json5 pages4loader.json5
.svn/
*/.svn/
.deploy_git/ .deploy_git/
*/.deploy_git/ */.deploy_git/
# HBuilder 目录
unpackage/ unpackage/
*/unpackage/ */unpackage/
Icon Icon
OneDrive/Icon OneDrive/Icon
# wrangler project
.dev.vars*
*/.dev.vars*
.wrangler/
*/.wrangler/
### seafile-ignore.local.txt ###