-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gateway): improve GO API interface, remove Writable API #145
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import ( | |
"github.com/ipfs/go-libipfs/gateway/assets" | ||
path "github.com/ipfs/go-path" | ||
"github.com/ipfs/go-path/resolver" | ||
options "github.com/ipfs/interface-go-ipfs-core/options" | ||
ipath "github.com/ipfs/interface-go-ipfs-core/path" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/trace" | ||
|
@@ -61,9 +60,15 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r * | |
|
||
// Check if directory has index.html, if so, serveFile | ||
idxPath := ipath.Join(contentPath, "index.html") | ||
idx, err := i.api.GetUnixFsNode(ctx, idxPath) | ||
idxResolvedPath, err := i.api.ResolvePath(ctx, idxPath) | ||
switch err.(type) { | ||
case nil: | ||
idx, err := i.api.GetUnixFsNode(ctx, idxResolvedPath) | ||
if err != nil { | ||
internalWebError(w, err) | ||
return | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the signature of the getter for UnixFS files: - GetUnixFsNode(context.Context, path.Path) (files.Node, error)
+ GetUnixFsNode(context.Context, path.Resolved) (files.Node, error) We already have |
||
f, ok := idx.(files.File) | ||
if !ok { | ||
internalWebError(w, files.ErrNotReader) | ||
|
@@ -104,14 +109,7 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r * | |
return | ||
} | ||
|
||
// Optimization: use Unixfs.Ls without resolving children, but using the | ||
// cumulative DAG size as the file size. This allows for a fast listing | ||
// while keeping a good enough Size field. | ||
results, err := i.api.LsUnixFsDir(ctx, | ||
resolvedPath, | ||
options.Unixfs.ResolveChildren(false), | ||
options.Unixfs.UseCumulativeSize(true), | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this optimization to Kubo's codebase. Each gateway implementation should use whatever they want, some might be faster, some slower. It's the implementers choice. This also allowed me to simplify the API signature to remove the options. - LsUnixFsDir(context.Context, path.Path, ...options.UnixfsLsOption) (<-chan iface.DirEntry, error)
+ LsUnixFsDir(context.Context, path.Resolved) (<-chan iface.DirEntry, error) |
||
results, err := i.api.LsUnixFsDir(ctx, resolvedPath) | ||
if err != nil { | ||
internalWebError(w, err) | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: something like
IPFSBackend
would be more descriptive, but can be changed later, won't block on this one thing (this interface will most likely get revamp in near future anyway)