feat: add support for directories in GetMetadataByCID

This commit is contained in:
Derrick Hammer 2024-01-09 16:34:07 -05:00
parent 712e216150
commit f6e005c497
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 11 additions and 0 deletions

View File

@ -17,6 +17,10 @@ type DirectoryMetadata struct {
var _ SerializableMetadata = (*DirectoryMetadata)(nil) var _ SerializableMetadata = (*DirectoryMetadata)(nil)
func NewEmptyDirectoryMetadata() *DirectoryMetadata {
return &DirectoryMetadata{}
}
func NewDirectoryMetadata(details DirectoryMetadataDetails, directories directoryReferenceMap, files fileReferenceMap, extraMetadata ExtraMetadata) *DirectoryMetadata { func NewDirectoryMetadata(details DirectoryMetadataDetails, directories directoryReferenceMap, files fileReferenceMap, extraMetadata ExtraMetadata) *DirectoryMetadata {
dirMetadata := &DirectoryMetadata{ dirMetadata := &DirectoryMetadata{
Details: details, Details: details,

View File

@ -306,6 +306,13 @@ func (n *NodeImpl) GetMetadataByCID(cid *encoding.CID) (md metadata.Metadata, er
case types.CIDTypeMetadataWebapp: case types.CIDTypeMetadataWebapp:
md = metadata.NewEmptyWebAppMetadata() md = metadata.NewEmptyWebAppMetadata()
err = msgpack.Unmarshal(bytes, md)
if err != nil {
return nil, err
}
case types.CIDTypeDirectory:
md = metadata.NewEmptyDirectoryMetadata()
err = msgpack.Unmarshal(bytes, md) err = msgpack.Unmarshal(bytes, md)
if err != nil { if err != nil {
return nil, err return nil, err