diff --git a/config/config.go b/config/config.go index 09b5ffbc..56965925 100644 --- a/config/config.go +++ b/config/config.go @@ -2471,3 +2471,26 @@ func GetNoRetMsg() bool { } return instance.Settings.NoRetMsg } + +func GetForceSsl() bool { + mu.RLock() + defer mu.RUnlock() + + if instance == nil { + fmt.Println("Warning: instance is nil when trying to ForceSSL value.") + return false + } + return instance.Settings.ForceSSL +} + +func GetHttpPortAfterSsl() string { + mu.RLock() + defer mu.RUnlock() + + if instance == nil { + fmt.Println("Warning: instance is nil when trying to get HttpPortAfterSSL.") + return "444" // 或者返回一个默认的 ImageLimit 值 + } + + return instance.Settings.HttpPortAfterSSL +} diff --git a/idmap/service.go b/idmap/service.go index 0c0ae205..1dbe49a8 100644 --- a/idmap/service.go +++ b/idmap/service.go @@ -456,7 +456,7 @@ func SimplifiedStoreIDv2(id string) (int64, error) { // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" || config.GetForceSsl(){ protocol = "https" } @@ -553,7 +553,7 @@ func StoreIDv2(id string) (int64, error) { // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -603,7 +603,7 @@ func StoreCachev2(id string) (int64, error) { // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -653,7 +653,7 @@ func StoreIDv2Pro(id string, subid string) (int64, int64, error) { // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -746,7 +746,7 @@ func RetrieveRowByIDv2Pro(newRowID string, newSubRowID string) (string, string, // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -817,7 +817,7 @@ func RetrieveRowByIDv2(rowid string) (string, error) { // 根据portValue确定协议 protocol := "http" portValue := config.GetPortValue() - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } if config.GetLotusGrpc() && config.GetLotusValue() { @@ -866,7 +866,7 @@ func RetrieveRowByCachev2(rowid string) (string, error) { // 根据portValue确定协议 protocol := "http" portValue := config.GetPortValue() - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } if config.GetLotusGrpc() && config.GetLotusValue() { @@ -947,7 +947,7 @@ func WriteConfigv2(sectionName, keyName, value string) error { // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -1023,7 +1023,7 @@ func DeleteConfigv2(sectionName, keyName string) error { // 根据portValue确定协议 protocol := "http" portValue := config.GetPortValue() - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -1072,7 +1072,7 @@ func ReadConfigv2(sectionName, keyName string) (string, error) { // 根据portValue确定协议 protocol := "http" portValue := config.GetPortValue() - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } if config.GetLotusGrpc() && config.GetLotusValue() { @@ -1236,7 +1236,7 @@ func UpdateVirtualValuev2(oldRowValue, newRowValue int64) error { serverDir := config.GetServer_dir() portValue := config.GetPortValue() protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } url := fmt.Sprintf("%s://%s:%s/getid?type=5&oldRowValue=%d&newRowValue=%d", protocol, serverDir, portValue, oldRowValue, newRowValue) @@ -1272,7 +1272,7 @@ func RetrieveRealValuev2(virtualValue int64) (string, string, error) { serverDir := config.GetServer_dir() portValue := config.GetPortValue() protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } url := fmt.Sprintf("%s://%s:%s/getid?type=6&virtualValue=%d", protocol, serverDir, portValue, virtualValue) @@ -1320,7 +1320,7 @@ func RetrieveVirtualValuev2(realValue string) (string, string, error) { // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -1374,7 +1374,7 @@ func RetrieveVirtualValuev2Pro(realValue string, realValueSub string) (string, s // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -1499,7 +1499,7 @@ func RetrieveRealValuesv2Pro(virtualValue int64, virtualValueSub int64) (string, // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -1593,7 +1593,7 @@ func UpdateVirtualValuev2Pro(oldVirtualValue1, newVirtualValue1, oldVirtualValue serverDir := config.GetServer_dir() portValue := config.GetPortValue() protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -1695,7 +1695,7 @@ func FindSubKeysByIdPro(id string) ([]string, error) { // 根据portValue确定协议 protocol := "http" - if portValue == "443" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" } diff --git a/images/upload_api.go b/images/upload_api.go index 67705aa6..913f00bc 100644 --- a/images/upload_api.go +++ b/images/upload_api.go @@ -177,7 +177,7 @@ func originalUploadBehavior(base64Image string) (string, error) { // 原有的UploadBase64ImageToServer函数的实现 protocol := "http" serverPort := config.GetPortValue() - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -194,9 +194,9 @@ func originalUploadBehavior(base64Image string) (string, error) { } serverDir := config.GetServer_dir() - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "http" - serverPort = "444" + serverPort = config.GetHttpPortAfterSsl() } if isPublicAddress(serverDir) { @@ -227,7 +227,7 @@ func UploadBehaviorV3(base64Image string) (string, int, int, error) { } else { protocol := "http" serverPort := config.GetPortValue() - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -241,9 +241,9 @@ func UploadBehaviorV3(base64Image string) (string, int, int, error) { } return resp, width, height, nil } else { - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "http" - serverPort = "444" + serverPort = config.GetHttpPortAfterSsl() } url = fmt.Sprintf("%s://127.0.0.1:%s/uploadpicv3", protocol, serverPort) @@ -261,7 +261,7 @@ func originalUploadBehaviorRecord(base64Image string) (string, error) { // 根据serverPort确定协议 protocol := "http" serverPort := config.GetPortValue() - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -278,9 +278,9 @@ func originalUploadBehaviorRecord(base64Image string) (string, error) { serverDir := config.GetServer_dir() // 当端口是443时,使用HTTP和444端口 - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "http" - serverPort = "444" + serverPort = config.GetHttpPortAfterSsl() } if isPublicAddress(serverDir) { diff --git a/oss/baidu.go b/oss/baidu.go index 36165d3e..05a5beec 100644 --- a/oss/baidu.go +++ b/oss/baidu.go @@ -133,7 +133,7 @@ func originalUploadBehavior(base64Image string) (string, error) { // 原有的UploadBase64ImageToServer函数的实现 protocol := "http" serverPort := config.GetPortValue() - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "https" } @@ -149,9 +149,9 @@ func originalUploadBehavior(base64Image string) (string, error) { } serverDir := config.GetServer_dir() - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "http" - serverPort = "444" + serverPort = config.GetHttpPortAfterSsl() } if isPublicAddress(serverDir) { diff --git a/server/uploadpic.go b/server/uploadpic.go index cd515af0..3c539d42 100644 --- a/server/uploadpic.go +++ b/server/uploadpic.go @@ -112,7 +112,7 @@ func UploadBase64ImageHandler(rateLimiter *RateLimiter) gin.HandlerFunc { } // 根据serverPort确定协议 protocol := "http" - if serverPort == "443" { + if serverPort == "443"||config.GetForceSsl() { protocol = "https" } stun, err := idmap.ReadConfigv2("stun", "addr") @@ -277,7 +277,7 @@ func UploadBase64RecordHandler(rateLimiter *RateLimiter) gin.HandlerFunc { // 根据serverPort确定协议 protocol := "http" - if serverPort == "443" { + if serverPort == "443" ||config.GetForceSsl(){ protocol = "https" } diff --git a/url/shorturl.go b/url/shorturl.go index 0d8381ad..a9726707 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" { + 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" { + if portValue == "443" ||config.GetForceSsl(){ protocol = "https" }