Skip to content

Commit a1eb9c7

Browse files
Mistragbalint
authored andcommitted
swarm/api/http: fixed list leaf links (#17342)
1 parent 00e6da9 commit a1eb9c7

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎swarm/api/http/server_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,16 +576,16 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
576576
pageFragments: []string{
577577
fmt.Sprintf("Swarm index of bzz:/%s/a/", ref),
578578
`<a class="normal-link" href="b/">b/</a>`,
579-
`<a class="normal-link" href="a">a</a>`,
579+
fmt.Sprintf(`<a class="normal-link" href="/bzz:/%s/a/a">a</a>`, ref),
580580
},
581581
},
582582
{
583583
path: "/a/b/",
584584
json: `{"entries":[{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/b/b","mod_time":"0001-01-01T00:00:00Z"},{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/b/c","mod_time":"0001-01-01T00:00:00Z"}]}`,
585585
pageFragments: []string{
586586
fmt.Sprintf("Swarm index of bzz:/%s/a/b/", ref),
587-
`<a class="normal-link" href="b">b</a>`,
588-
`<a class="normal-link" href="c">c</a>`,
587+
fmt.Sprintf(`<a class="normal-link" href="/bzz:/%s/a/b/b">b</a>`, ref),
588+
fmt.Sprintf(`<a class="normal-link" href="/bzz:/%s/a/b/c">c</a>`, ref),
589589
},
590590
},
591591
{

‎swarm/api/http/templates.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package http
1818

1919
import (
2020
"encoding/hex"
21+
"fmt"
2122
"html/template"
2223
"path"
2324

@@ -45,7 +46,10 @@ func init() {
4546
{
4647
templateName: "bzz-list",
4748
partial: bzzList,
48-
funcs: template.FuncMap{"basename": path.Base},
49+
funcs: template.FuncMap{
50+
"basename": path.Base,
51+
"leaflink": leafLink,
52+
},
4953
},
5054
{
5155
templateName: "landing-page",
@@ -62,6 +66,10 @@ func init() {
6266
faviconBytes = bytes
6367
}
6468

69+
func leafLink(URI api.URI, manifestEntry api.ManifestEntry) string {
70+
return fmt.Sprintf("/bzz:/%s/%s", URI.Addr, manifestEntry.Path)
71+
}
72+
6573
const bzzList = `{{ define "content" }}
6674
<h3 class="top-space">Swarm index of {{ .URI }}</h3>
6775
<hr>
@@ -83,10 +91,11 @@ const bzzList = `{{ define "content" }}
8391
<td>DIR</td>
8492
<td>-</td>
8593
</tr>
86-
{{ end }} {{ range .List.Entries }}
94+
{{ end }}
95+
{{ range .List.Entries }}
8796
<tr>
8897
<td>
89-
<a class="normal-link" href="{{ basename .Path }}">{{ basename .Path }}</a>
98+
<a class="normal-link" href="{{ leaflink $.URI . }}">{{ basename .Path }}</a>
9099
</td>
91100
<td>{{ .ContentType }}</td>
92101
<td>{{ .Size }}</td>

0 commit comments

Comments
 (0)