Compare commits

...

3 Commits

2 changed files with 11 additions and 0 deletions

View File

@@ -190,11 +190,13 @@ func GetTphPicsFromMessageWithReply(ctx *ext.Context, update *ext.Update) (*type
ctx.Reply(update, ext.ReplyTextString("解析 telegraph 路径失败: "+err.Error()), nil) ctx.Reply(update, ext.ReplyTextString("解析 telegraph 路径失败: "+err.Error()), nil)
return nil, nil, dispatcher.EndGroups return nil, nil, dispatcher.EndGroups
} }
tphdir = strings.TrimSpace(tphdir)
msg, err := ctx.Reply(update, ext.ReplyTextString("正在获取 telegraph 页面..."), nil) msg, err := ctx.Reply(update, ext.ReplyTextString("正在获取 telegraph 页面..."), nil)
if err != nil { if err != nil {
logger.Errorf("Failed to reply to update: %s", err) logger.Errorf("Failed to reply to update: %s", err)
return nil, nil, dispatcher.EndGroups return nil, nil, dispatcher.EndGroups
} }
logger.Debugf("Fetching telegraph page: %s", pagepath)
page, err := tphutil.DefaultClient().GetPage(ctx, pagepath) page, err := tphutil.DefaultClient().GetPage(ctx, pagepath)
if err != nil { if err != nil {
logger.Errorf("Failed to get telegraph page: %s", err) logger.Errorf("Failed to get telegraph page: %s", err)
@@ -222,6 +224,10 @@ func GetTphPicsFromMessageWithReply(ctx *ext.Context, update *ext.Update) (*type
} }
if node.Tag == "img" { if node.Tag == "img" {
if src, ok := node.Attrs["src"]; ok { if src, ok := node.Attrs["src"]; ok {
if strings.HasPrefix(src, "/file/") {
// handle images on telegra.ph server
src = "https://telegra.ph" + src
}
imgs = append(imgs, src) imgs = append(imgs, src)
} }
} }

View File

@@ -2,6 +2,7 @@ package tphutil
import ( import (
"encoding/json" "encoding/json"
"strings"
"github.com/krau/SaveAny-Bot/config" "github.com/krau/SaveAny-Bot/config"
"github.com/krau/SaveAny-Bot/pkg/telegraph" "github.com/krau/SaveAny-Bot/pkg/telegraph"
@@ -41,6 +42,10 @@ func GetNodeImages(node telegraph.Node) []string {
if nodeElement.Tag == "img" { if nodeElement.Tag == "img" {
if src, exists := nodeElement.Attrs["src"]; exists { if src, exists := nodeElement.Attrs["src"]; exists {
if strings.HasPrefix(src, "/file/") {
// handle images on telegra.ph server
src = "https://telegra.ph" + src
}
srcs = append(srcs, src) srcs = append(srcs, src)
} }
} }