mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
show hash if not in original url
Change the template handler to pass the hash to the directory listing template if the original url doesn't contain the hash. The directory listing template will display the hash in grey under the original url if the hash is passed to it. License: MIT Signed-off-by: Jack Loughran <j@ckloughran.com>
This commit is contained in:
parent
5fce2df907
commit
9ef1486307
@ -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
|
||||
@ -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
|
||||
@ -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"),
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -347,11 +347,17 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
|
||||
}
|
||||
}
|
||||
|
||||
var hash string
|
||||
if !strings.Contains(originalUrlPath, "ipfs") {
|
||||
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 {
|
||||
|
||||
@ -14,6 +14,7 @@ type listingTemplateData struct {
|
||||
Listing []directoryItem
|
||||
Path string
|
||||
BackLink string
|
||||
Hash string
|
||||
}
|
||||
|
||||
type directoryItem struct {
|
||||
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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) {
|
||||
|
||||
@ -195,8 +195,9 @@
|
||||
},
|
||||
{
|
||||
"author": "lgierth",
|
||||
"hash": "QmdZ4PvPHFQVLLEve7DgoKDcSY19wwpGBB1GKjjKi2rEL1",
|
||||
"name": "dir-index-html"
|
||||
"hash": "QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV",
|
||||
"name": "dir-index-html",
|
||||
"version": "1.0.4"
|
||||
},
|
||||
{
|
||||
"author": "Kubuxu",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user