fix notify

This commit is contained in:
“xHuPo” 2024-08-30 18:11:42 +08:00
parent 040f21820e
commit f78e228351

View file

@ -3,6 +3,7 @@ package main
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -55,20 +56,15 @@ var rootCmd = &cobra.Command{
flist := strings.Split(FILE, "/") flist := strings.Split(FILE, "/")
f := fmt.Sprintf("%s.%s", flist[len(flist)-1], file_type) f := fmt.Sprintf("%s.%s", flist[len(flist)-1], file_type)
if title == "" { // title_value := getEnvStr("TITLE", title)
if os.Getenv("TITLE") != "" { // if title_value == "" {
title, _ = readFile(os.Getenv("TITLE")) // title = "获取不到title或环境变量TITLE"
} else { // }
title = "获取不到title或环境变量TITLE" t_encode := decodeBase64(title)
} title = t_encode
}
if msg == "" { m_encode := decodeBase64(msg)
if os.Getenv("MSG") != "" { msg = m_encode
msg, _ = readFile(os.Getenv("MSG"))
} else {
msg = "获取不到msg或环境变量MSG"
}
}
// 如果配置文件中提供飞书链接,则通知用户 // 如果配置文件中提供飞书链接,则通知用户
if notify != "" { if notify != "" {
@ -232,10 +228,35 @@ func s3PutObject(ak, sk, endpoint, bucket, inputKey, filePath, url string) (stri
return "", err return "", err
} }
func readFile(path string) (string, error) { // func readFile(path string) (string, error) {
data, err := os.ReadFile(path) // 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 { 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
// }