feat: split off meta parsing to ParseMetadata
This commit is contained in:
parent
fc212ef246
commit
cc2964e80f
|
@ -331,25 +331,38 @@ func (s *StorageService) GetMetadataByCID(cid *encoding.CID) (md metadata.Metada
|
|||
return nil, err
|
||||
}
|
||||
|
||||
md, err = s.ParseMetadata(bytes, cid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.metadataCache.Put(hashStr, md)
|
||||
|
||||
return md, nil
|
||||
}
|
||||
|
||||
func (s *StorageService) ParseMetadata(bytes []byte, cid *encoding.CID) (metadata.Metadata, error) {
|
||||
var md metadata.Metadata
|
||||
|
||||
switch cid.Type {
|
||||
case types.CIDTypeMetadataMedia, types.CIDTypeBridge: // Both cases use the same deserialization method
|
||||
md = metadata.NewEmptyMediaMetadata()
|
||||
|
||||
err = msgpack.Unmarshal(bytes, md)
|
||||
err := msgpack.Unmarshal(bytes, md)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case types.CIDTypeMetadataWebapp:
|
||||
md = metadata.NewEmptyWebAppMetadata()
|
||||
|
||||
err = msgpack.Unmarshal(bytes, md)
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -357,7 +370,5 @@ func (s *StorageService) GetMetadataByCID(cid *encoding.CID) (md metadata.Metada
|
|||
return nil, ErrUnsupportedMetaFormat
|
||||
}
|
||||
|
||||
s.metadataCache.Put(hashStr, md)
|
||||
|
||||
return md, nil
|
||||
}
|
||||
|
|
|
@ -15,5 +15,6 @@ type StorageService interface {
|
|||
DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error)
|
||||
DownloadBytesByCID(cid *encoding.CID) ([]byte, error)
|
||||
GetMetadataByCID(cid *encoding.CID) (metadata.Metadata, error)
|
||||
ParseMetadata(bytes []byte, cid *encoding.CID) (metadata.Metadata, error)
|
||||
Service
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue