feat: add CID method
This commit is contained in:
parent
6cac5c6a28
commit
7b7c705c0d
|
@ -3,6 +3,8 @@ package storage
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||||
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||||
"git.lumeweb.com/LumeWeb/portal/db/models"
|
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||||
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
||||||
"io"
|
"io"
|
||||||
|
@ -18,6 +20,7 @@ type File struct {
|
||||||
hash []byte
|
hash []byte
|
||||||
storage interfaces.StorageService
|
storage interfaces.StorageService
|
||||||
record *models.Upload
|
record *models.Upload
|
||||||
|
cid *encoding.CID
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFile(hash []byte, storage interfaces.StorageService) *File {
|
func NewFile(hash []byte, storage interfaces.StorageService) *File {
|
||||||
|
@ -145,3 +148,11 @@ func (f *File) Size() uint64 {
|
||||||
|
|
||||||
return record.Size
|
return record.Size
|
||||||
}
|
}
|
||||||
|
func (f *File) CID() *encoding.CID {
|
||||||
|
if f.cid == nil {
|
||||||
|
multihash := encoding.MultihashFromBytes(f.Hash(), types.HashTypeBlake3)
|
||||||
|
cid := encoding.NewCID(types.CIDTypeRaw, *multihash, f.Size())
|
||||||
|
f.cid = cid
|
||||||
|
}
|
||||||
|
return f.cid
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue