|
|
|
@ -22,45 +22,50 @@ var assetLock sync.Mutex
@@ -22,45 +22,50 @@ var assetLock sync.Mutex
|
|
|
|
|
var imageExtensions = []string{"png", "jpg", "jpeg", "gif", "svg", "webp"} |
|
|
|
|
|
|
|
|
|
func rewriteURL(u string, loc *url.URL) string { |
|
|
|
|
if daemonAddress != "" { |
|
|
|
|
scheme := "gemini" |
|
|
|
|
if strings.HasPrefix(loc.Path, "/file/") { |
|
|
|
|
scheme = "file" |
|
|
|
|
} |
|
|
|
|
if daemonAddress == "" { |
|
|
|
|
return u |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if strings.HasPrefix(u, "file://") { |
|
|
|
|
if !allowFileAccess { |
|
|
|
|
return "http://" + daemonAddress + "/?FileAccessNotAllowed" |
|
|
|
|
} |
|
|
|
|
return "http://" + daemonAddress + "/file/" + u[7:] |
|
|
|
|
} |
|
|
|
|
if loc.Path == "" { |
|
|
|
|
loc.Path = "/" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
offset := 0 |
|
|
|
|
if strings.HasPrefix(u, "gemini://") { |
|
|
|
|
offset = 9 |
|
|
|
|
} |
|
|
|
|
firstSlash := strings.IndexRune(u[offset:], '/') |
|
|
|
|
if firstSlash != -1 { |
|
|
|
|
u = strings.ToLower(u[:firstSlash+offset]) + u[firstSlash+offset:] |
|
|
|
|
scheme := "gemini" |
|
|
|
|
if strings.HasPrefix(loc.Path, "/file/") { |
|
|
|
|
scheme = "file" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if strings.HasPrefix(u, "file://") { |
|
|
|
|
if !allowFileAccess { |
|
|
|
|
return "http://" + daemonAddress + "/?FileAccessNotAllowed" |
|
|
|
|
} |
|
|
|
|
return "http://" + daemonAddress + "/file/" + u[7:] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if strings.HasPrefix(u, "gemini://") { |
|
|
|
|
return "http://" + daemonAddress + "/gemini/" + u[9:] |
|
|
|
|
} else if strings.Contains(u, "://") { |
|
|
|
|
return u |
|
|
|
|
} else if loc != nil && len(u) > 0 && !strings.HasPrefix(u, "//") { |
|
|
|
|
if u[0] != '/' { |
|
|
|
|
if loc.Path[len(loc.Path)-1] == '/' { |
|
|
|
|
u = path.Join("/", loc.Path, u) |
|
|
|
|
} else { |
|
|
|
|
u = path.Join("/", path.Dir(loc.Path), u) |
|
|
|
|
} |
|
|
|
|
offset := 0 |
|
|
|
|
if strings.HasPrefix(u, "gemini://") { |
|
|
|
|
offset = 9 |
|
|
|
|
} |
|
|
|
|
firstSlash := strings.IndexRune(u[offset:], '/') |
|
|
|
|
if firstSlash != -1 { |
|
|
|
|
u = strings.ToLower(u[:firstSlash+offset]) + u[firstSlash+offset:] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if strings.HasPrefix(u, "gemini://") { |
|
|
|
|
return "http://" + daemonAddress + "/gemini/" + u[9:] |
|
|
|
|
} else if strings.Contains(u, "://") { |
|
|
|
|
return u |
|
|
|
|
} else if loc != nil && len(u) > 0 && !strings.HasPrefix(u, "//") { |
|
|
|
|
if u[0] != '/' { |
|
|
|
|
if loc.Path[len(loc.Path)-1] == '/' { |
|
|
|
|
u = path.Join("/", loc.Path, u) |
|
|
|
|
} else { |
|
|
|
|
u = path.Join("/", path.Dir(loc.Path), u) |
|
|
|
|
} |
|
|
|
|
return "http://" + daemonAddress + "/" + scheme + "/" + strings.ToLower(loc.Host) + u |
|
|
|
|
} |
|
|
|
|
return "http://" + daemonAddress + "/" + scheme + "/" + u |
|
|
|
|
return "http://" + daemonAddress + "/" + scheme + "/" + strings.ToLower(loc.Host) + u |
|
|
|
|
} |
|
|
|
|
return u |
|
|
|
|
return "http://" + daemonAddress + "/" + scheme + "/" + u |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newPage() []byte { |
|
|
|
|