@@ -12,6 +12,7 @@ import (
12
12
13
13
ipldlegacy "github.com/ipfs/go-ipld-legacy"
14
14
ipath "github.com/ipfs/interface-go-ipfs-core/path"
15
+ dih "github.com/ipfs/kubo/assets/dag-index-html"
15
16
"github.com/ipfs/kubo/tracing"
16
17
"github.com/ipld/go-ipld-prime"
17
18
"github.com/ipld/go-ipld-prime/multicodec"
@@ -117,29 +118,16 @@ func (i *gatewayHandler) serveCodec(ctx context.Context, w http.ResponseWriter,
117
118
}
118
119
119
120
func (i * gatewayHandler ) serveCodecHTML (ctx context.Context , w http.ResponseWriter , r * http.Request , resolvedPath ipath.Resolved , contentPath ipath.Path ) {
120
- codecName := mc .Code (resolvedPath .Cid ().Prefix ().Codec ).String ()
121
- body := fmt .Sprintf (`<!DOCTYPE html>
122
- <html lang="en">
123
- <head>
124
- <meta charset="utf-8" />
125
- </head>
126
- <body>
127
- <p>Requested CID <code>%q</code> uses <code>%q</code> codec.</p>
128
- <ul>
129
- <li><a href="?format=json" rel="nofollow">Preview as JSON</a> (<code>application/json</code>)</li>
130
- <li>Download as
131
- <ul>
132
- <li><a href="?format=raw" rel="nofollow">Raw Block</a> (no conversion)</li>
133
- <li><a href="?format=dag-json" rel="nofollow">DAG-JSON</a> (specs at <a href="https://ipld.io/specs/codecs/dag-json/spec/" rel="noreferrer nofollow">IPLD</a> and <a href="https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-json" rel="noreferrer nofollow">IANA</a>)</li>
134
- <li><a href="?format=dag-cbor" rel="nofollow">DAG-CBOR</a> (specs at <a href="https://ipld.io/specs/codecs/dag-cbor/spec/" rel="noreferrer nofollow">IPLD</a> and <a href="https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-cbor" rel="noreferrer nofollow">IANA</a>)</li>
135
- </ul>
136
- </li>
137
- </ul>
138
- </body>
139
- </html>
140
- ` , resolvedPath .Cid (), codecName )
141
-
142
- _ , _ = w .Write ([]byte (body ))
121
+ // TODO: cache-control/etag like for DirIndex
122
+ cidCodec := mc .Code (resolvedPath .Cid ().Prefix ().Codec )
123
+ if err := dih .DagIndexTemplate .Execute (w , dih.DagIndexTemplateData {
124
+ Path : contentPath .String (),
125
+ CID : resolvedPath .Cid ().String (),
126
+ CodecName : cidCodec .String (),
127
+ CodecHex : fmt .Sprintf ("0x%x" , uint64 (cidCodec )),
128
+ }); err != nil {
129
+ webError (w , "failed to generate HTML listing for this DAG: retry without 'Accept: text/html'" , err , http .StatusInternalServerError )
130
+ }
143
131
}
144
132
145
133
func (i * gatewayHandler ) serveCodecRaw (ctx context.Context , w http.ResponseWriter , r * http.Request , resolvedPath ipath.Resolved , contentPath ipath.Path , contentType string ) {
0 commit comments