feat: updated models for notification

This commit is contained in:
Marvin Zhang
2024-07-11 18:08:40 +08:00
parent 87b6eb3cef
commit 6998a7cfe5
3 changed files with 14 additions and 7 deletions

View File

@@ -6,3 +6,8 @@ const (
NotificationTriggerTaskEmptyResults = "task_empty_results"
NotificationTriggerTaskNever = "task_never"
)
const (
NotificationTemplateModeRichText = "rich-text"
NotificationTemplateModeMarkdown = "markdown"
)

View File

@@ -9,7 +9,9 @@ type NotificationSettingV2 struct {
Enabled bool `json:"enabled" bson:"enabled"`
Global bool `json:"global" bson:"global"`
Title string `json:"title,omitempty" bson:"title,omitempty"`
Template string `json:"template,omitempty" bson:"template,omitempty"`
TemplateMode string `json:"template_mode" bson:"template_mode"`
TemplateMarkdown string `json:"template_markdown,omitempty" bson:"template_markdown,omitempty"`
TemplateRichText string `json:"template_rich_text,omitempty" bson:"template_rich_text,omitempty"`
TaskTrigger string `json:"task_trigger" bson:"task_trigger"`
Mail NotificationSettingMail `json:"mail,omitempty" bson:"mail,omitempty"`
Mobile NotificationSettingMobile `json:"mobile,omitempty" bson:"mobile,omitempty"`

View File

@@ -48,7 +48,7 @@ func (svc *ServiceV2) initData() (err error) {
Description: "这是默认的邮件通知。您可以使用您自己的设置进行编辑。",
TaskTrigger: constants.NotificationTriggerTaskFinish,
Title: "[Crawlab] 爬虫任务更新: {{$.status}}",
Template: `尊敬的 {{$.user.username}},
TemplateMarkdown: `尊敬的 {{$.user.username}},
请查看下面的任务数据。
@@ -83,7 +83,7 @@ func (svc *ServiceV2) initData() (err error) {
Description: "This is the default mail notification. You can edit it with your own settings",
TaskTrigger: constants.NotificationTriggerTaskFinish,
Title: "[Crawlab] Task Update: {{$.status}}",
Template: `Dear {{$.user.username}},
TemplateMarkdown: `Dear {{$.user.username}},
Please find the task data as below.
@@ -118,7 +118,7 @@ Please find the task data as below.
Description: "这是默认的手机通知。您可以使用您自己的设置进行编辑。",
TaskTrigger: constants.NotificationTriggerTaskFinish,
Title: "[Crawlab] 任务更新: {{$.status}}",
Template: `尊敬的 {{$.user.username}},
TemplateMarkdown: `尊敬的 {{$.user.username}},
请查看下面的任务数据。
@@ -146,7 +146,7 @@ Please find the task data as below.
Description: "This is the default mobile notification. You can edit it with your own settings",
TaskTrigger: constants.NotificationTriggerTaskFinish,
Title: "[Crawlab] Task Update: {{$.status}}",
Template: `Dear {{$.user.username}},
TemplateMarkdown: `Dear {{$.user.username}},
Please find the task data as below.
@@ -208,7 +208,7 @@ func (svc *ServiceV2) SendMail(s *models.NotificationSettingV2, entity bson.M) (
}
// content
content, err := parser.Parse(s.Template, entity)
content, err := parser.Parse(s.TemplateMarkdown, entity)
if err != nil {
log.Warnf("parsing 'content' error: %v", err)
}
@@ -238,7 +238,7 @@ func (svc *ServiceV2) SendMobile(s *models.NotificationSettingV2, entity bson.M)
}
// content
content, err := parser.Parse(s.Template, entity)
content, err := parser.Parse(s.TemplateMarkdown, entity)
if err != nil {
log.Warnf("parsing 'content' error: %v", err)
}