From f63d567b533b04ebabca23a10c5e8a6c629ad21d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 1 Mar 2024 21:32:06 -0500 Subject: [PATCH] refactor: add support for using a passed cid type --- api/s5/file.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/api/s5/file.go b/api/s5/file.go index 2fd2cf6..7697153 100644 --- a/api/s5/file.go +++ b/api/s5/file.go @@ -27,6 +27,7 @@ type S5File struct { record *metadata.UploadMetadata protocol *s5.S5Protocol cid *encoding.CID + typ types.CIDType read bool tus *s5.TusHandler ctx context.Context @@ -36,6 +37,7 @@ type FileParams struct { Storage storage.StorageService Metadata metadata.MetadataService Hash []byte + Type types.CIDType Protocol *s5.S5Protocol Tus *s5.TusHandler } @@ -45,6 +47,7 @@ func NewFile(params FileParams) *S5File { storage: params.Storage, metadata: params.Metadata, hash: params.Hash, + typ: params.Type, protocol: params.Protocol, tus: params.Tus, ctx: context.Background(), @@ -112,7 +115,6 @@ func (f *S5File) Close() error { func (f *S5File) init(offset int64) error { if f.reader == nil { - reader, err := f.tus.GetUploadReader(f.ctx, f.hash, offset) if err == nil { @@ -196,7 +198,13 @@ func (f *S5File) Size() uint64 { func (f *S5File) CID() *encoding.CID { if f.cid == nil { multihash := encoding.MultihashFromBytes(f.Hash(), types.HashTypeBlake3) - cid := encoding.NewCID(types.CIDTypeRaw, *multihash, f.Size()) + + typ := f.typ + if typ == 0 { + typ = types.CIDTypeRaw + } + + cid := encoding.NewCID(typ, *multihash, f.Size()) f.cid = cid } return f.cid