Skip to content

Commit

Permalink
Merge pull request #5830 from jackloughran/feat/gateway/always-show-hash
Browse files Browse the repository at this point in the history
Show hash on gateway
  • Loading branch information
Stebalien authored Jan 5, 2019
2 parents 5fce2df + 65fc4b4 commit f98652c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 30 deletions.
6 changes: 3 additions & 3 deletions assets/assets.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go-bindata -pkg=assets -prefix=$GOPATH/src/gx/ipfs/QmdZ4PvPHFQVLLEve7DgoKDcSY19wwpGBB1GKjjKi2rEL1 init-doc $GOPATH/src/gx/ipfs/QmdZ4PvPHFQVLLEve7DgoKDcSY19wwpGBB1GKjjKi2rEL1/dir-index-html
//go:generate go-bindata -pkg=assets -prefix=$GOPATH/src/gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV init-doc $GOPATH/src/gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV/dir-index-html
//go:generate gofmt -w bindata.go

package assets
Expand All @@ -15,7 +15,7 @@ import (
uio "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/io"

// this import keeps gx from thinking the dep isn't used
_ "gx/ipfs/QmdZ4PvPHFQVLLEve7DgoKDcSY19wwpGBB1GKjjKi2rEL1/dir-index-html"
_ "gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV/dir-index-html"
)

// initDocPaths lists the paths for the docs we want to seed during --init
Expand All @@ -34,7 +34,7 @@ func SeedInitDocs(nd *core.IpfsNode) (cid.Cid, error) {
return addAssetList(nd, initDocPaths)
}

var initDirPath = filepath.Join(os.Getenv("GOPATH"), "gx", "ipfs", "QmdZ4PvPHFQVLLEve7DgoKDcSY19wwpGBB1GKjjKi2rEL1", "dir-index-html")
var initDirPath = filepath.Join(os.Getenv("GOPATH"), "gx", "ipfs", "QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV", "dir-index-html")
var initDirIndex = []string{
filepath.Join(initDirPath, "knownIcons.txt"),
filepath.Join(initDirPath, "dir-index.html"),
Expand Down
50 changes: 25 additions & 25 deletions assets/bindata.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,17 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
}
}

var hash string
if !strings.HasPrefix(originalUrlPath, ipfsPathPrefix) {
hash = resolvedPath.Cid().String()
}

// See comment above where originalUrlPath is declared.
tplData := listingTemplateData{
Listing: dirListing,
Path: originalUrlPath,
BackLink: backLink,
Hash: hash,
}
err = listingTemplate.Execute(w, tplData)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions core/corehttp/gateway_indexPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type listingTemplateData struct {
Listing []directoryItem
Path string
BackLink string
Hash string
}

type directoryItem struct {
Expand Down
15 changes: 15 additions & 0 deletions core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn2.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing at root
req, err = http.NewRequest("GET", ts.URL, nil)
Expand Down Expand Up @@ -435,6 +438,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn1.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing
req, err = http.NewRequest("GET", ts.URL+"/foo%3F%20%23%3C%27/bar/", nil)
Expand Down Expand Up @@ -465,6 +471,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/bar/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn3.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing with prefix
req, err = http.NewRequest("GET", ts.URL, nil)
Expand Down Expand Up @@ -496,6 +505,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/good-prefix/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn1.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing with illegal prefix
req, err = http.NewRequest("GET", ts.URL, nil)
Expand Down Expand Up @@ -535,6 +547,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn1.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}
}

func TestCacheControlImmutable(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@
},
{
"author": "lgierth",
"hash": "QmdZ4PvPHFQVLLEve7DgoKDcSY19wwpGBB1GKjjKi2rEL1",
"name": "dir-index-html"
"hash": "QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV",
"name": "dir-index-html",
"version": "1.0.4"
},
{
"author": "Kubuxu",
Expand Down

0 comments on commit f98652c

Please sign in to comment.