diff --git a/artalk-go.example.yml b/artalk-go.example.yml index 4d65cf2..b067451 100644 --- a/artalk-go.example.yml +++ b/artalk-go.example.yml @@ -106,9 +106,8 @@ email: enabled: false # 总开关 send_type: "smtp" # 发送方式 [smtp, ali_dm, sendmail] send_name: '{{reply_nick}}' # 发信人昵称 - send_addr: "example@qq.com" # 发信人地址 + send_addr: "noreply@example.com" # 发信人地址 mail_subject: "[{{site_name}}] 您收到了来自 @{{reply_nick}} 的回复" - mail_subject_to_admin: '[{{site_name}}] 您的文章 "{{page_title}}" 有新回复' mail_tpl: "default" # 邮件模板文件 smtp: host: "smtp.qq.com" @@ -118,7 +117,7 @@ email: ali_dm: # https://help.aliyun.com/document_detail/29444.html access_key_id: "" # 阿里云颁发给用户的访问服务所用的密钥 ID access_key_secret: "" # 用于加密的密钥 - account_name: "example@example.com" # 管理控制台中配置的发信地址 + account_name: "noreply@example.com" # 管理控制台中配置的发信地址 # 图片上传 img_upload: @@ -132,38 +131,21 @@ img_upload: exec: "./upgit -c -t /artalk-img" del_local: true # 上传后删除本地的图片 -# 其他通知方式 -notify: +# 管理员多元推送 +admin_notify: + # 邮件通知管理员 + email: + enabled: true + mail_subject: '[{{site_name}}] 您的文章 "{{page_title}}" 有新回复' # Telegram telegram: enabled: false api_token: "" receivers: - 7777777 - # 飞书 - lark: - enabled: false - webhook_url: "" - # 钉钉 - ding_talk: - enabled: false - token: "" - secret: "" # Bark bark: enabled: false server: "http://day.app/xxxxxxx/" - # Slack - slack: - enabled: false - oauth_token: "" - receivers: - - "CHANNEL_ID" - # LINE - line: - enabled: false - channel_secret: "" - channel_access_token: "" - receivers: - - "USER_ID_1" - - "GROUP_ID_1" + # 另支持 飞书机器人、钉钉、Slack、LINE 等更多推送方式 + # 详情参考:https://artalk.js.org/guide/backend/notify.html diff --git a/config/config.go b/config/config.go index a4c6916..5d78eb6 100644 --- a/config/config.go +++ b/config/config.go @@ -5,26 +5,27 @@ import "time" // Config 配置 // @link https://godoc.org/github.com/mitchellh/mapstructure type Config struct { - AppKey string `mapstructure:"app_key" json:"app_key"` // 加密密钥 - Debug bool `mapstructure:"debug" json:"debug"` // 调试模式 - TimeZone string `mapstructure:"timezone" json:"timezone"` // 时区 - Host string `mapstructure:"host" json:"host"` // HTTP Server 监听 IP - Port int `mapstructure:"port" json:"port"` // HTTP Server 监听 Port - DB DBConf `mapstructure:"db" json:"db"` // 数据文件 - Cache CacheConf `mapstructure:"cache" json:"cache"` // 缓存 - Log LogConf `mapstructure:"log" json:"log"` // 日志文件 - AllowOrigins []string `mapstructure:"allow_origins" json:"allow_origins"` // @deprecated 已废弃 (请使用 TrustedDomains) - TrustedDomains []string `mapstructure:"trusted_domains" json:"trusted_domains"` // 可信任的域名 (新) - SSL SSLConf `mapstructure:"ssl" json:"ssl"` // SSL - SiteDefault string `mapstructure:"site_default" json:"site_default"` // 默认站点名(当请求无指定 site_name 时使用) - AdminUsers []AdminUserConf `mapstructure:"admin_users" json:"admin_users"` // 管理员账户 - LoginTimeout int `mapstructure:"login_timeout" json:"login_timeout"` // 登陆超时 - Moderator ModeratorConf `mapstructure:"moderator" json:"moderator"` // 评论审查 - Captcha CaptchaConf `mapstructure:"captcha" json:"captcha"` // 验证码 - Email EmailConf `mapstructure:"email" json:"email"` // 邮箱提醒 - ImgUpload ImgUploadConf `mapstructure:"img_upload" json:"img_upload"` // 图片上传 - Notify NotifyConf `mapstructure:"notify" json:"notify"` // 其他通知方式 - Frontend FrontendConf `mapstructure:"frontend" json:"frontend"` + AppKey string `mapstructure:"app_key" json:"app_key"` // 加密密钥 + Debug bool `mapstructure:"debug" json:"debug"` // 调试模式 + TimeZone string `mapstructure:"timezone" json:"timezone"` // 时区 + Host string `mapstructure:"host" json:"host"` // HTTP Server 监听 IP + Port int `mapstructure:"port" json:"port"` // HTTP Server 监听 Port + DB DBConf `mapstructure:"db" json:"db"` // 数据文件 + Cache CacheConf `mapstructure:"cache" json:"cache"` // 缓存 + Log LogConf `mapstructure:"log" json:"log"` // 日志文件 + AllowOrigins []string `mapstructure:"allow_origins" json:"allow_origins"` // @deprecated 已废弃 (请使用 TrustedDomains) + TrustedDomains []string `mapstructure:"trusted_domains" json:"trusted_domains"` // 可信任的域名 (新) + SSL SSLConf `mapstructure:"ssl" json:"ssl"` // SSL + SiteDefault string `mapstructure:"site_default" json:"site_default"` // 默认站点名(当请求无指定 site_name 时使用) + AdminUsers []AdminUserConf `mapstructure:"admin_users" json:"admin_users"` // 管理员账户 + LoginTimeout int `mapstructure:"login_timeout" json:"login_timeout"` // 登陆超时 + Moderator ModeratorConf `mapstructure:"moderator" json:"moderator"` // 评论审查 + Captcha CaptchaConf `mapstructure:"captcha" json:"captcha"` // 验证码 + Email EmailConf `mapstructure:"email" json:"email"` // 邮箱提醒 + ImgUpload ImgUploadConf `mapstructure:"img_upload" json:"img_upload"` // 图片上传 + AdminNotify AdminNotifyConf `mapstructure:"admin_notify" json:"admin_notify"` // 其他通知方式 + Notify *AdminNotifyConf `mapstructure:"notify" json:"notify"` // @deprecated 已废弃 (请使用 AdminNotify) + Frontend FrontendConf `mapstructure:"frontend" json:"frontend"` } type DBConf struct { @@ -141,7 +142,7 @@ type EmailConf struct { SendName string `mapstructure:"send_name" json:"send_name"` // 发件人名 SendAddr string `mapstructure:"send_addr" json:"send_addr"` // 发件人地址 MailSubject string `mapstructure:"mail_subject" json:"mail_subject"` // 邮件标题 - MailSubjectToAdmin string `mapstructure:"mail_subject_to_admin" json:"mail_subject_to_admin"` // 邮件标题 (发送给管理员用) + MailSubjectToAdmin string `mapstructure:"mail_subject_to_admin" json:"mail_subject_to_admin"` // @deprecated 已废弃 (请使用 AdminNotify.Email.MailSubject) - 邮件标题 (发送给管理员用) MailTpl string `mapstructure:"mail_tpl" json:"mail_tpl"` // 邮件模板 SMTP SMTPConf `mapstructure:"smtp" json:"smtp"` // SMTP 配置 AliDM AliDMConf `mapstructure:"ali_dm" json:"ali_dm"` // 阿里云邮件配置 @@ -216,7 +217,8 @@ type UpgitConf struct { } // 其他通知方式 -type NotifyConf struct { +type AdminNotifyConf struct { + Email EmailConf `mapstructure:"email" json:"email"` // 邮件通知 Telegram NotifyTelegramConf `mapstructure:"telegram" json:"telegram"` // TG Lark NotifyLarkConf `mapstructure:"lark" json:"lark"` // 飞书 DingTalk NotifyDingTalkConf `mapstructure:"ding_talk" json:"ding_talk"` // 钉钉 diff --git a/config/init.go b/config/init.go index bddcaa7..69b74ea 100644 --- a/config/init.go +++ b/config/init.go @@ -88,7 +88,7 @@ func postInit() { Instance.Captcha.Always = true } - // 检查废弃需更新配置 + /* 检查废弃需更新配置 */ if Instance.Captcha.ActionTimeout != 0 { logrus.Warn("captcha.action_timeout 配置项已废弃,请使用 captcha.action_reset 代替") if Instance.Captcha.ActionReset == 0 { @@ -101,4 +101,14 @@ func postInit() { Instance.TrustedDomains = Instance.AllowOrigins } } + + // @version < 2.2.0 + if Instance.Notify != nil { + logrus.Warn("notify 配置项已废弃,请使用 admin_notify 代替") + Instance.AdminNotify = *Instance.Notify + } + if Instance.Email.MailSubjectToAdmin != "" { + logrus.Warn("email.mail_subject_to_admin 配置项已废弃,请使用 admin_notify.email.mail_subject 代替") + Instance.AdminNotify.Email.MailSubject = Instance.Email.MailSubjectToAdmin + } } diff --git a/lib/email/email.go b/lib/email/email.go index f839945..a46dd5a 100644 --- a/lib/email/email.go +++ b/lib/email/email.go @@ -57,7 +57,7 @@ func AsyncSendToAdmin(notify *model.Notify, admin *model.User) { } fromName := RenderCommon(config.Instance.Email.SendName, notify, from, to) - subject := RenderCommon(config.Instance.Email.MailSubjectToAdmin, notify, from, to) + subject := RenderCommon(config.Instance.AdminNotify.Email.MailSubjectToAdmin, notify, from, to) body := RenderEmailTpl(notify, from, to) AddToQueue(Email{ diff --git a/model/notify_launcher/init.go b/model/notify_launcher/init.go index 4e1daea..03e2086 100644 --- a/model/notify_launcher/init.go +++ b/model/notify_launcher/init.go @@ -19,7 +19,7 @@ func Init() { email.InitQueue() // Telegram - tgConf := config.Instance.Notify.Telegram + tgConf := config.Instance.AdminNotify.Telegram if tgConf.Enabled { telegramService, _ := telegram.New(tgConf.ApiToken) telegramService.AddReceivers(tgConf.Receivers...) @@ -27,14 +27,14 @@ func Init() { } // 钉钉 - dingTalkConf := config.Instance.Notify.DingTalk + dingTalkConf := config.Instance.AdminNotify.DingTalk if dingTalkConf.Enabled { dingTalkService := dingding.New(&dingding.Config{Token: dingTalkConf.Token, Secret: dingTalkConf.Secret}) notify.UseServices(dingTalkService) } // Slack - slackConf := config.Instance.Notify.Slack + slackConf := config.Instance.AdminNotify.Slack if slackConf.Enabled { slackService := slack.New(slackConf.OauthToken) slackService.AddReceivers(slackConf.Receivers...) @@ -42,9 +42,9 @@ func Init() { } // LINE - LINEConf := config.Instance.Notify.LINE + LINEConf := config.Instance.AdminNotify.LINE if LINEConf.Enabled { - lineService, _ := line.New(config.Instance.Notify.LINE.ChannelSecret, config.Instance.Notify.LINE.ChannelAccessToken) + lineService, _ := line.New(config.Instance.AdminNotify.LINE.ChannelSecret, config.Instance.AdminNotify.LINE.ChannelAccessToken) lineService.AddReceivers(LINEConf.Receivers...) notify.UseServices(lineService) } diff --git a/model/notify_launcher/notify_launcher.go b/model/notify_launcher/notify_launcher.go index 1a6aa96..5652f74 100644 --- a/model/notify_launcher/notify_launcher.go +++ b/model/notify_launcher/notify_launcher.go @@ -122,7 +122,7 @@ func AdminNotify(comment *model.Comment, pComment *model.Comment) { // 飞书发送 func SendLark(msg string) { - larkConf := config.Instance.Notify.Lark + larkConf := config.Instance.AdminNotify.Lark if !larkConf.Enabled { return } @@ -139,7 +139,7 @@ func SendLark(msg string) { // Bark 发送 func SendBark(title string, msg string) { - barkConf := config.Instance.Notify.Bark + barkConf := config.Instance.AdminNotify.Bark if !barkConf.Enabled { return }