Fix Windows remote URL detection

This commit is contained in:
lutc5
2026-05-06 16:58:27 +08:00
parent 22f793c188
commit a87b2eefe4
3 changed files with 55 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
@@ -25,6 +26,8 @@ const (
modelListPath = "/algo/api/v2/model/list"
)
var remoteBaseURLPattern = regexp.MustCompile(`https?://[^\s"'<>),\]}]+`)
type Config struct {
BaseURL string
AuthFile string
@@ -535,12 +538,16 @@ func uniqueStrings(values []string) []string {
}
func extractBaseURLFromText(text string) string {
matches := remoteBaseURLPattern.FindAllString(text, -1)
for i := len(matches) - 1; i >= 0; i-- {
if value := normalizeRemoteBaseURLHint(matches[i]); value != "" {
return value
}
}
for _, marker := range []string{
"endpoint config:",
"Using service url:",
"Download asset from:",
"https://ai-lingma",
"https://lingma",
} {
if value := extractBaseURLAfterMarker(text, marker); value != "" {
return value
@@ -574,10 +581,16 @@ func normalizeRemoteBaseURLHint(raw string) string {
if raw == "" {
return ""
}
if strings.HasPrefix(raw, "ttps://") {
raw = "h" + raw
}
parsed, err := url.Parse(raw)
if err != nil || parsed.Scheme == "" || parsed.Host == "" {
return ""
}
if parsed.Scheme != "http" && parsed.Scheme != "https" {
return ""
}
host := strings.ToLower(parsed.Host)
if !strings.Contains(host, "lingma") && !strings.Contains(host, "rdc.aliyuncs.com") {
return ""