* refactor: a big refactor. wip * refactor: port handle file * refactor: place all handlers * fix: task info nil pointer * feat: enhance task progress tracking and context management * feat: cancel task * feat: stream mode * feat: silent mode * feat: dir cmd * refactor: remove unused old file * feat: rule cmd * feat: handle silent mode * feat: batch task * fix: batch task progress and temp file cleanup * refactor: update file creation and cleanup methods for better resource management * feat: add save command with silent mode handling * feat: message link * feat: update message prompts to include file count in storage selection * feat: slient save links * refactor: reduce dup code * feat: rule type * feat: chose dir * feat: refactor file handling and storage rules, improve error handling and logging * feat: rule mode * feat: telegraph pics * fix: tphpics nil pointer and inaccurate dirpath * feat: silent save telegraph * feat: add suffix to avoid file overwrite * feat: new storage telegram * chore: tidy go mod
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package tphutil
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/krau/SaveAny-Bot/config"
|
|
"github.com/krau/SaveAny-Bot/pkg/telegraph"
|
|
)
|
|
|
|
var tphClient *telegraph.Client
|
|
|
|
func DefaultClient() *telegraph.Client {
|
|
if tphClient != nil {
|
|
return tphClient
|
|
}
|
|
if config.Cfg.Telegram.Proxy.Enable && config.Cfg.Telegram.Proxy.URL != "" {
|
|
proxyUrl := config.Cfg.Telegram.Proxy.URL
|
|
var err error
|
|
tphClient, err = telegraph.NewClientWithProxy(proxyUrl)
|
|
if err != nil {
|
|
tphClient = telegraph.NewClient()
|
|
}
|
|
} else {
|
|
tphClient = telegraph.NewClient()
|
|
}
|
|
return tphClient
|
|
}
|
|
|
|
func GetNodeImages(node telegraph.Node) []string {
|
|
var srcs []string
|
|
|
|
var nodeElement telegraph.NodeElement
|
|
data, err := json.Marshal(node)
|
|
if err != nil {
|
|
return srcs
|
|
}
|
|
err = json.Unmarshal(data, &nodeElement)
|
|
if err != nil {
|
|
return srcs
|
|
}
|
|
|
|
if nodeElement.Tag == "img" {
|
|
if src, exists := nodeElement.Attrs["src"]; exists {
|
|
srcs = append(srcs, src)
|
|
}
|
|
}
|
|
for _, child := range nodeElement.Children {
|
|
srcs = append(srcs, GetNodeImages(child)...)
|
|
}
|
|
return srcs
|
|
}
|