From 958820cd3e5a4204f6f02a8cd2a32786d43a5a4f Mon Sep 17 00:00:00 2001 From: joncrall Date: Tue, 17 Oct 2023 13:15:07 -0400 Subject: [PATCH 1/3] Support symlinks and other types in ls --- ipfsspec/core.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ipfsspec/core.py b/ipfsspec/core.py index cdd881b..55c4571 100644 --- a/ipfsspec/core.py +++ b/ipfsspec/core.py @@ -15,6 +15,14 @@ class IPFSGateway: + """ + Abstrats the IPFS gateway REST API. + + Documentation for the REST API can be found here: [Kubo_RPC_API]_. + + References: + .. [Kubo_RPC_API] http://docs.ipfs.tech.ipns.localhost:8080/reference/kubo/rpc/ + """ def __init__(self, url): self.url = url self.state = "unknown" @@ -166,7 +174,23 @@ def ls(self, path, detail=True, **kwargs): logger.debug("ls on %s", path) res = self._gw_apipost("ls", arg=path) links = res["Objects"][0]["Links"] - types = {1: "directory", 2: "file"} + + # Documentation for the type codes doesn't seem to have a great location. + # Currently 2023-10-17, the ls API docs specify the ls return + # structure, but not what the type integers mean: + # http://docs.ipfs.tech.ipns.localhost:8080/reference/kubo/rpc/#api-v0-ls + # Some information about type codes can be found here: + # https://ipfs-search.readthedocs.io/en/latest/ipfs_datatypes.html + # https://github.com/ipfs/go-unixfs/blob/master/pb/unixfs.proto + + types = { + 0: "raw", + 1: "directory", + 2: "file", + 3: "metadata", + 4: "symlink", + 5: "shard", + } if detail: return [{"name": path + "/" + link["Name"], "size": link["Size"], From 884147aba7c06c3c080f3cf7f254673ca65573fd Mon Sep 17 00:00:00 2001 From: Jon Crall Date: Tue, 17 Oct 2023 14:37:22 -0400 Subject: [PATCH 2/3] Update ipfsspec/core.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tobias Kölling --- ipfsspec/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipfsspec/core.py b/ipfsspec/core.py index 55c4571..4a9a481 100644 --- a/ipfsspec/core.py +++ b/ipfsspec/core.py @@ -178,7 +178,7 @@ def ls(self, path, detail=True, **kwargs): # Documentation for the type codes doesn't seem to have a great location. # Currently 2023-10-17, the ls API docs specify the ls return # structure, but not what the type integers mean: - # http://docs.ipfs.tech.ipns.localhost:8080/reference/kubo/rpc/#api-v0-ls + # http://docs.ipfs.tech/reference/kubo/rpc/#api-v0-ls # Some information about type codes can be found here: # https://ipfs-search.readthedocs.io/en/latest/ipfs_datatypes.html # https://github.com/ipfs/go-unixfs/blob/master/pb/unixfs.proto From 67fcb42e110dbce991c147738f6e9111539dc0b1 Mon Sep 17 00:00:00 2001 From: joncrall Date: Tue, 17 Oct 2023 18:07:52 -0400 Subject: [PATCH 3/3] Add more ls types to async code --- ipfsspec/async_ipfs.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ipfsspec/async_ipfs.py b/ipfsspec/async_ipfs.py index 06d3c9e..6506883 100644 --- a/ipfsspec/async_ipfs.py +++ b/ipfsspec/async_ipfs.py @@ -66,7 +66,14 @@ async def ls(self, path, session): res = await self.api_get("ls", session, arg=path) self._raise_not_found_for_status(res, path) resdata = await res.json() - types = {1: "directory", 2: "file"} + types = { + 0: "raw", + 1: "directory", + 2: "file", + 3: "metadata", + 4: "symlink", + 5: "shard", + } return [{ "name": path + "/" + link["Name"], "CID": link["Hash"],