From 576321be5ff6e3412e870f7d02331c3781cdfcac Mon Sep 17 00:00:00 2001 From: fghwett <1058178245@qq.com> Date: Mon, 28 Aug 2023 17:02:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BD=BF=E7=94=A8webhook=E5=92=8Ccustom?= =?UTF-8?q?=E9=80=9A=E9=81=93=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E6=97=B6?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=86=85=E5=AE=B9=E4=B8=AD=E5=8C=85=E5=90=AB?= =?UTF-8?q?\n=E4=BC=9A=E6=8E=A8=E9=80=81=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/custom.go | 10 +++++----- common/utils.go | 5 +++++ controller/webhook.go | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/channel/custom.go b/channel/custom.go index 7e96daacc..61743aa6f 100644 --- a/channel/custom.go +++ b/channel/custom.go @@ -18,11 +18,11 @@ func SendCustomMessage(message *model.Message, user *model.User, channel_ *model return errors.New("自定义通道不能使用本服务地址") } template := channel_.Other - template = strings.Replace(template, "$url", message.URL, -1) - template = strings.Replace(template, "$to", message.To, -1) - template = strings.Replace(template, "$title", message.Title, -1) - template = strings.Replace(template, "$description", message.Description, -1) - template = strings.Replace(template, "$content", message.Content, -1) + template = common.Replace(template, "$url", message.URL, -1) + template = common.Replace(template, "$to", message.To, -1) + template = common.Replace(template, "$title", message.Title, -1) + template = common.Replace(template, "$description", message.Description, -1) + template = common.Replace(template, "$content", message.Content, -1) reqBody := []byte(template) resp, err := http.Post(url, "application/json", bytes.NewReader(reqBody)) if err != nil { diff --git a/common/utils.go b/common/utils.go index bf6145bc3..380f5aa6d 100644 --- a/common/utils.go +++ b/common/utils.go @@ -159,3 +159,8 @@ func Markdown2HTML(markdown string) (HTML string, err error) { func GetTimestamp() int64 { return time.Now().Unix() } + +func Replace(s, old, new string, n int) string { + new = strings.TrimPrefix(strings.TrimSuffix(fmt.Sprintf("%q", new), "\""), "\"") + return strings.Replace(s, old, new, n) +} diff --git a/controller/webhook.go b/controller/webhook.go index f4deeb990..8b90cc32c 100644 --- a/controller/webhook.go +++ b/controller/webhook.go @@ -240,7 +240,7 @@ func TriggerWebhook(c *gin.Context) { } for key, value := range extractRule { variableValue := gjson.Get(reqText, value).String() - webhook.ConstructRule = strings.Replace(webhook.ConstructRule, "$"+key, variableValue, -1) + webhook.ConstructRule = common.Replace(webhook.ConstructRule, "$"+key, variableValue, -1) } constructRule := model.WebhookConstructRule{} err = json.Unmarshal([]byte(webhook.ConstructRule), &constructRule) From a35fc0c0476da9dccd711434d2a8e7f8590c7400 Mon Sep 17 00:00:00 2001 From: fghwett <1058178245@qq.com> Date: Wed, 11 Oct 2023 09:48:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0markdown=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=EF=BC=8C=E8=AE=BF=E9=97=AE=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0GFM=E6=8B=93=E5=B1=95?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/utils.go | 6 +++++- web/src/components/MessagesTable.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/utils.go b/common/utils.go index 380f5aa6d..7611b2f09 100644 --- a/common/utils.go +++ b/common/utils.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/google/uuid" "github.com/yuin/goldmark" + "github.com/yuin/goldmark/extension" "html/template" "log" "net" @@ -148,7 +149,10 @@ func Markdown2HTML(markdown string) (HTML string, err error) { return "", nil } var buf bytes.Buffer - err = goldmark.Convert([]byte(markdown), &buf) + goldMarkEntity := goldmark.New( + goldmark.WithExtensions(extension.GFM), + ) + err = goldMarkEntity.Convert([]byte(markdown), &buf) if err != nil { return fmt.Sprintf("Markdown 渲染出错:%s", err.Error()), err } diff --git a/web/src/components/MessagesTable.js b/web/src/components/MessagesTable.js index ac3de2e7b..2b7bdfaa5 100644 --- a/web/src/components/MessagesTable.js +++ b/web/src/components/MessagesTable.js @@ -5,6 +5,7 @@ import { API, openPage, showError, showSuccess, showWarning } from '../helpers'; import { ITEMS_PER_PAGE } from '../constants'; import { renderTimestamp } from '../helpers/render'; import { Link } from 'react-router-dom'; +import { marked } from 'marked'; function renderStatus(status) { switch (status) { @@ -416,7 +417,7 @@ const MessagesTable = () => { ) : ( '' )} - {message.content ?

{message.content}

: ''} + {message.content ?
: ''}