fix(gw): links in CID column on dir listing

This switches go-ipfs to dir-index-html after
https://github.com/ipfs/dir-index-html/pull/43
got merged to master
parent cd1feb3a
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,5 +2,5 @@
package assets
const (
BindataVersionHash = "514e5ae28d8adb84955801b56ef47aca44bf9cc8"
BindataVersionHash = "605b5945438e1fe2eaf8a6571cca7ecda12d5599"
)
Subproject commit 9603194e10c40ca8585497828fc4a7b7c72dea90
Subproject commit 92efd3dfd1cdaf2ca50b34b2b5d1243c5dcc8af7
......@@ -391,13 +391,16 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
gwURL = ""
}
dnslink := hasDNSLinkOrigin(gwURL, urlPath)
// See comment above where originalUrlPath is declared.
tplData := listingTemplateData{
GatewayURL: gwURL,
DNSLink: dnslink,
Listing: dirListing,
Size: size,
Path: urlPath,
Breadcrumbs: breadcrumbs(urlPath, gwURL),
Breadcrumbs: breadcrumbs(urlPath, dnslink),
BackLink: backLink,
Hash: hash,
}
......
......@@ -13,6 +13,7 @@ import (
// structs for directory listing
type listingTemplateData struct {
GatewayURL string
DNSLink bool
Listing []directoryItem
Size string
Path string
......@@ -34,7 +35,7 @@ type breadcrumb struct {
Path string
}
func breadcrumbs(urlPath string, gwRootURL string) []breadcrumb {
func breadcrumbs(urlPath string, dnslinkOrigin bool) []breadcrumb {
var ret []breadcrumb
p, err := ipfspath.ParsePath(urlPath)
......@@ -43,7 +44,6 @@ func breadcrumbs(urlPath string, gwRootURL string) []breadcrumb {
return ret
}
segs := p.Segments()
ns := segs[0]
contentRoot := segs[1]
for i, seg := range segs {
if i == 0 {
......@@ -56,10 +56,11 @@ func breadcrumbs(urlPath string, gwRootURL string) []breadcrumb {
}
}
// Drop the /ipns/<fqdn> prefix from breadcrumb Paths when directory listing
// on a DNSLink website (loaded due to Host header in HTTP request).
// Necessary because gwRootURL won't have a public gateway mounted.
if ns == "ipns" && (("//" + contentRoot) == gwRootURL) {
// Drop the /ipns/<fqdn> prefix from breadcrumb Paths when directory
// listing on a DNSLink website (loaded due to Host header in HTTP
// request). Necessary because the hostname most likely won't have a
// public gateway mounted.
if dnslinkOrigin {
prefix := "/ipns/" + contentRoot
for i, crumb := range ret {
if strings.HasPrefix(crumb.Path, prefix) {
......@@ -77,6 +78,16 @@ func shortHash(hash string) string {
return (hash[0:4] + "\u2026" + hash[len(hash)-4:])
}
// helper to detect DNSLink website context
// (when hostname from gwURL is matching /ipns/<fqdn> in path)
func hasDNSLinkOrigin(gwURL string, path string) bool {
if gwURL != "" {
dnslinkRoot := strings.Replace(gwURL, "//", "/ipns/", 1)
return strings.HasPrefix(path, dnslinkRoot)
}
return false
}
var listingTemplate *template.Template
func init() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment