Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,18 @@ func GetTransferUrl() bool {
return instance.Settings.TransferUrl
}

// 获取CustomDomain的值
func GetCustomUrl() string {
mu.RLock()
defer mu.RUnlock()

if instance == nil {
fmt.Println("Warning: instance is nil when trying to GetCustomDomain value.")
return ""
}
return instance.Settings.CustomUrl
}

// 获取 HTTP 地址
func GetHttpAddress() string {
mu.RLock()
Expand Down
3 changes: 3 additions & 0 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,9 @@ func transformMessageTextUrl(messageText string, message callapi.ActionMessage,
mylog.Printf("转换url:%v", originalURL)
shortURL := url.GenerateShortURL(originalURL)
return shortURL
} else if config.GetCustomUrl() != "" {
shortURL := url.GenerateShortURL(originalURL)
return url.GetCustomUrl() + "/url/" + shortURL
} else {
// 自己是主节点
shortURL := url.GenerateShortURL(originalURL)
Expand Down
27 changes: 14 additions & 13 deletions structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ type Settings struct {
EnableWsServer bool `yaml:"enable_ws_server"`
WsServerToken string `yaml:"ws_server_token"`
//ssl和链接转换类
IdentifyFile bool `yaml:"identify_file"`
IdentifyAppids []int64 `yaml:"identify_appids"`
Crt string `yaml:"crt"`
Key string `yaml:"key"`
UseSelfCrt bool `yaml:"use_self_crt"`
WebhookPath string `yaml:"webhook_path"`
WebhookPrefixIp []string `yaml:"webhook_prefix_ip"`
ForceSSL bool `yaml:"force_ssl"`
HttpPortAfterSSL string `yaml:"http_port_after_ssl"`
IdentifyFile bool `yaml:"identify_file"`
IdentifyAppids []int64 `yaml:"identify_appids"`
Crt string `yaml:"crt"`
Key string `yaml:"key"`
UseSelfCrt bool `yaml:"use_self_crt"`
WebhookPath string `yaml:"webhook_path"`
WebhookPrefixIp []string `yaml:"webhook_prefix_ip"`
ForceSSL bool `yaml:"force_ssl"`
HttpPortAfterSSL string `yaml:"http_port_after_ssl"`
//日志类
DeveloperLog bool `yaml:"developer_log"`
LogLevel int `yaml:"log_level"`
Expand Down Expand Up @@ -137,10 +137,11 @@ type Settings struct {
StringOb11 bool `yaml:"string_ob11"`
StringAction bool `yaml:"string_action"`
//url相关
VisibleIp bool `yaml:"visible_ip"`
UrlToQrimage bool `yaml:"url_to_qrimage"`
QrSize int `yaml:"qr_size"`
TransferUrl bool `yaml:"transfer_url"`
VisibleIp bool `yaml:"visible_ip"`
UrlToQrimage bool `yaml:"url_to_qrimage"`
QrSize int `yaml:"qr_size"`
TransferUrl bool `yaml:"transfer_url"`
CustomUrl string `yaml:"custom_url"`
//框架修改
Title string `yaml:"title"`
FrpPort string `yaml:"frp_port"`
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ settings:
url_to_qrimage : false #将信息中的url转换为二维码单独作为图片发出,需要同时设置 #SSL配置类 机器人发送URL设置 的 transfer_url 为 true visible_ip也需要为true
qr_size : 200 #二维码尺寸,单位像素
transfer_url : true #默认开启,关闭后自理url发送,配置server_dir为你的域名,配置crt和key后,将域名/url和/image在q.qq.com后台通过校验,自动使用302跳转处理机器人发出的所有域名.
custom_url : "" #自定义url,当你的port设置为非443端口,又需要转换url时,可以设置此项,使用反代等手段将url转发到qq机器人服务器

#框架修改
title : "Gensokyo © 2023 - Hoshinonyaruko" #程序的标题 如果多个机器人 可根据标题区分
Expand Down
10 changes: 8 additions & 2 deletions url/shorturl.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func GenerateShortURL(longURL string) string {
// 根据portValue确定协议
protocol := "http"
portValue := config.GetPortValue()
if portValue == "443" ||config.GetForceSsl(){
if portValue == "443" || config.GetForceSsl() {
protocol = "https"
}

Expand Down Expand Up @@ -242,7 +242,7 @@ func getLongURLFromDB(shortURL string) (string, error) {
// 根据portValue确定协议
protocol := "http"
portValue := config.GetPortValue()
if portValue == "443" ||config.GetForceSsl(){
if portValue == "443" || config.GetForceSsl() {
protocol = "https"
}

Expand Down Expand Up @@ -361,6 +361,12 @@ func GetBaseURL() string {
return "https://" + serverDir
}

// 自定义短链接url
func GetCustomUrl() string {
customUrl := config.GetCustomUrl()
return "https://" + customUrl
}

// RedirectFromShortURLHandler
func RedirectFromShortURLHandler(c *gin.Context) {
shortURL := c.Param("shortURL")
Expand Down