From f78e2283512091c24ebe0cbd8f39652f68d0a306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CxHuPo=E2=80=9D?= <7513325+vrocwang@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:11:42 +0800 Subject: [PATCH] fix notify --- scripts/notify/main.go | 57 +++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/scripts/notify/main.go b/scripts/notify/main.go index 19b9d0b..06f8c22 100644 --- a/scripts/notify/main.go +++ b/scripts/notify/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "encoding/base64" "encoding/json" "fmt" "net/http" @@ -55,20 +56,15 @@ var rootCmd = &cobra.Command{ flist := strings.Split(FILE, "/") f := fmt.Sprintf("%s.%s", flist[len(flist)-1], file_type) - if title == "" { - if os.Getenv("TITLE") != "" { - title, _ = readFile(os.Getenv("TITLE")) - } else { - title = "获取不到title或环境变量TITLE" - } - } - if msg == "" { - if os.Getenv("MSG") != "" { - msg, _ = readFile(os.Getenv("MSG")) - } else { - msg = "获取不到msg或环境变量MSG" - } - } + // title_value := getEnvStr("TITLE", title) + // if title_value == "" { + // title = "获取不到title或环境变量TITLE" + // } + t_encode := decodeBase64(title) + title = t_encode + + m_encode := decodeBase64(msg) + msg = m_encode // 如果配置文件中提供飞书链接,则通知用户 if notify != "" { @@ -232,10 +228,35 @@ func s3PutObject(ak, sk, endpoint, bucket, inputKey, filePath, url string) (stri return "", err } -func readFile(path string) (string, error) { - data, err := os.ReadFile(path) +// func readFile(path string) (string, error) { +// data, err := os.ReadFile(path) +// if err != nil { +// return "", err +// } +// return string(data), nil +// } + +func decodeBase64(str string) string { + data, err := base64.StdEncoding.DecodeString(str) if err != nil { - return "", err + return str } - return string(data), nil + reencode := base64.StdEncoding.EncodeToString(data) + if reencode != str { + return str + } + return string(data) } + +// func getEnvStr(key, defaultValue string) string { +// v, ok := os.LookupEnv(key) +// if !ok { +// return defaultValue +// } +// value := strings.TrimSpace(v) +// if value == "" { +// return "" +// } +// return value + +// }