🎨 Support configuration of cloud provider connectivity check URL https://github.com/siyuan-note/siyuan/issues/7805

This commit is contained in:
Liang Ding 2023-03-29 14:20:19 +08:00
parent 98d2d7587d
commit 0f912cf1b3
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 26 additions and 4 deletions

View file

@ -18,6 +18,7 @@ package util
import (
"net/http"
"net/url"
"strings"
"time"
@ -82,6 +83,11 @@ func InvalidIDPattern(idArg string, result *gulu.Result) bool {
return true
}
func IsValidURL(str string) bool {
_, err := url.Parse(str)
return nil == err
}
func initHttpClient() {
http.DefaultClient = httpclient.GetCloudFileClient2Min()
http.DefaultTransport = httpclient.NewTransport(false)

View file

@ -156,6 +156,20 @@ func NormalizeEndpoint(endpoint string) string {
return endpoint
}
func NormalizeCheckURL(checkURL string) string {
checkURL = strings.TrimSpace(checkURL)
if "" == checkURL {
return ""
}
if !strings.HasPrefix(checkURL, "http://") && !strings.HasPrefix(checkURL, "https://") {
checkURL = "http://" + checkURL
}
if !IsValidURL(checkURL) {
return ""
}
return checkURL
}
func FilterMoveDocFromPaths(fromPaths []string, toPath string) (ret []string) {
tmp := FilterSelfChildDocs(fromPaths)
for _, fromPath := range tmp {