fix notify
This commit is contained in:
parent
040f21820e
commit
f78e228351
1 changed files with 39 additions and 18 deletions
|
@ -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
|
||||
|
||||
// }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue