|
@@ -14,6 +14,7 @@ import (
|
|
|
"eta/eta_api/services/alarm_msg"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "github.com/PuerkitoBio/goquery"
|
|
|
"github.com/rdlucklib/rdluck_tools/file"
|
|
|
"github.com/rdlucklib/rdluck_tools/http"
|
|
|
html2 "golang.org/x/net/html"
|
|
@@ -1943,40 +1944,41 @@ func processMapTable(data map[string]interface{}, reportId, fromScene int) error
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// HandleReportContent
|
|
|
-// @Description: 处理报告内容(动态图表/表格添加授权token)
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2025-01-07 10:03:15
|
|
|
-// @param body string
|
|
|
-// @return newBody string
|
|
|
-func HandleReportContent(body string, opType string, tokenMap map[string]string) (newBody string) {
|
|
|
- if body == `` {
|
|
|
- return
|
|
|
- }
|
|
|
- newBody = body
|
|
|
-
|
|
|
- // 解析HTML
|
|
|
- doc, err := html2.Parse(strings.NewReader(body))
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error parsing HTML:", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- replaceIframeSrc(doc, opType, tokenMap)
|
|
|
-
|
|
|
- // 输出修改后的HTML
|
|
|
- var modifiedHtml strings.Builder
|
|
|
- err = html2.Render(&modifiedHtml, doc)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error rendering HTML:", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- newBody = modifiedHtml.String()
|
|
|
- fmt.Println(newBody)
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
+//
|
|
|
+//// HandleReportContent
|
|
|
+//// @Description: 处理报告内容(动态图表/表格添加授权token)
|
|
|
+//// @author: Roc
|
|
|
+//// @datetime 2025-01-07 10:03:15
|
|
|
+//// @param body string
|
|
|
+//// @return newBody string
|
|
|
+//func HandleReportContent(body string, opType string, tokenMap map[string]string) (newBody string) {
|
|
|
+// if body == `` {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// newBody = body
|
|
|
+//
|
|
|
+// // 解析HTML
|
|
|
+// doc, err := html2.Parse(strings.NewReader(body))
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("Error parsing HTML:", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// replaceIframeSrc(doc, opType, tokenMap)
|
|
|
+//
|
|
|
+// // 输出修改后的HTML
|
|
|
+// var modifiedHtml strings.Builder
|
|
|
+// err = html2.Render(&modifiedHtml, doc)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("Error rendering HTML:", err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// newBody = modifiedHtml.String()
|
|
|
+// fmt.Println(newBody)
|
|
|
+//
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
// replaceIframeSrc 遍历HTML节点,替换iframe的src属性
|
|
|
func replaceIframeSrc(n *html2.Node, opType string, tokenMap map[string]string) {
|
|
@@ -2346,3 +2348,36 @@ func FilterShareUrl() web.FilterFunc {
|
|
|
utils.ApiLog.Info(fmt.Sprintf("原始请求为:%s, 已修改请求路径为:%s?%s", path, newPath, q.Encode()))
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// HandleReportContent
|
|
|
+// @Description: 处理报告内容(动态图表/表格添加授权token)
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2025-01-07 10:03:15
|
|
|
+// @param body string
|
|
|
+// @return newBody string
|
|
|
+func HandleReportContent(body string, opType string, tokenMap map[string]string) (newBody string) {
|
|
|
+ if body == `` {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newBody = body
|
|
|
+ doc, err := goquery.NewDocumentFromReader(strings.NewReader(newBody))
|
|
|
+ if err != nil {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ doc.Find("iframe").Each(func(i int, f *goquery.Selection) {
|
|
|
+ src, exist := f.Attr("src")
|
|
|
+ if exist {
|
|
|
+ var newLink string
|
|
|
+ switch opType {
|
|
|
+ case `add`:
|
|
|
+ newLink = linkAddToken(src, tokenMap)
|
|
|
+ case `del`:
|
|
|
+ newLink = linkDelToken(src)
|
|
|
+ }
|
|
|
+ f.SetAttr("src", newLink)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ newBody, _ = doc.Find("body").Children().Html()
|
|
|
+ return newBody
|
|
|
+}
|