提交 cfb6196e 作者: Lars Gierth 提交者: alice

WIP-without-assets

License: MIT
Signed-off-by: 's avatarLars Gierth <larsg@systemli.org>
上级 5a42289a
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -45,6 +45,16 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac ...@@ -45,6 +45,16 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac
return nil, err return nil, err
} }
// Shortcut for when there's not really anything to resolve.
seg := ipath.Segments()
if len(seg) == 2 && seg[0] == "ipfs" {
root, err := cid.Decode(seg[1])
if err != nil {
return nil, err
}
return coreiface.NewResolvedPath(ipath, root, root, ""), nil
}
var resolveOnce resolver.ResolveOnce var resolveOnce resolver.ResolveOnce
switch ipath.Segments()[0] { switch ipath.Segments()[0] {
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"html/template"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
...@@ -269,11 +270,12 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr ...@@ -269,11 +270,12 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return return
} }
goget := r.URL.Query().Get("go-get") == "1"
ixnd, err := dirr.Find(ctx, "index.html") ixnd, err := dirr.Find(ctx, "index.html")
switch { switch {
case err == nil: case err == nil:
dirwithoutslash := urlPath[len(urlPath)-1] != '/' dirwithoutslash := urlPath[len(urlPath)-1] != '/'
goget := r.URL.Query().Get("go-get") == "1"
if dirwithoutslash && !goget { if dirwithoutslash && !goget {
// See comment above where originalUrlPath is declared. // See comment above where originalUrlPath is declared.
http.Redirect(w, r, originalUrlPath+"/", 302) http.Redirect(w, r, originalUrlPath+"/", 302)
...@@ -306,6 +308,15 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr ...@@ -306,6 +308,15 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return return
} }
var meta []template.HTML
if goget {
seg := path.FromString(parsedPath.String()).Segments()
fmt.Printf("goget seg: %+v\n", seg)
metatpl := `<meta name="go-import" content="%[1]s git https://%[1]s/.git">`
dvcsimport := "e45e73dd.ngrok.io" + parsedPath.String()
meta = append(meta, template.HTML(fmt.Sprintf(metatpl, dvcsimport)))
}
// storage for directory listing // storage for directory listing
var dirListing []directoryItem var dirListing []directoryItem
dirr.ForEachLink(ctx, func(link *ipld.Link) error { dirr.ForEachLink(ctx, func(link *ipld.Link) error {
...@@ -352,6 +363,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr ...@@ -352,6 +363,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
Listing: dirListing, Listing: dirListing,
Path: originalUrlPath, Path: originalUrlPath,
BackLink: backLink, BackLink: backLink,
Meta: meta,
} }
err = listingTemplate.Execute(w, tplData) err = listingTemplate.Execute(w, tplData)
if err != nil { if err != nil {
......
...@@ -14,6 +14,7 @@ type listingTemplateData struct { ...@@ -14,6 +14,7 @@ type listingTemplateData struct {
Listing []directoryItem Listing []directoryItem
Path string Path string
BackLink string BackLink string
Meta []template.HTML
} }
type directoryItem struct { type directoryItem struct {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论