diff --git a/config/config.go b/config/config.go index 5696592..04ef0c9 100644 --- a/config/config.go +++ b/config/config.go @@ -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() diff --git a/handlers/message_parser.go b/handlers/message_parser.go index 7970b97..232272b 100644 --- a/handlers/message_parser.go +++ b/handlers/message_parser.go @@ -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) diff --git a/structs/structs.go b/structs/structs.go index e2ff14a..91e5328 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -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"` @@ -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"` diff --git a/template/config_template.go b/template/config_template.go index 0a9eb8b..c72b201 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -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" #程序的标题 如果多个机器人 可根据标题区分 diff --git a/url/shorturl.go b/url/shorturl.go index a972670..81b9cf5 100644 --- a/url/shorturl.go +++ b/url/shorturl.go @@ -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" } @@ -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" } @@ -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")