fix: encode size as uint64 to the end of the cid
This commit is contained in:
parent
479df7eb39
commit
5aca66d919
|
@ -1,11 +1,16 @@
|
|||
package cid
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/multiformats/go-multibase"
|
||||
)
|
||||
|
||||
func EncodeHashSimple(hash [32]byte) (string, error) {
|
||||
func EncodeHashSimple(hash [32]byte, size uint64) (string, error) {
|
||||
sizeBytes := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(sizeBytes, size)
|
||||
|
||||
prefixedHash := append([]byte{0x26, 0x1f}, hash[:]...)
|
||||
prefixedHash = append(prefixedHash, sizeBytes...)
|
||||
|
||||
return multibase.Encode(multibase.Base58BTC, prefixedHash)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func InitFiles() {
|
|||
func (f *FilesService) PostUpload() {
|
||||
ctx := f.Ctx
|
||||
|
||||
file, _, err := f.Ctx.FormFile("file")
|
||||
file, meta, err := f.Ctx.FormFile("file")
|
||||
if internalErrorCustom(ctx, err, errors.New("invalid file data")) {
|
||||
return
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (f *FilesService) PostUpload() {
|
|||
|
||||
hashBytes := blake3.Sum256(buf.Bytes())
|
||||
hashHex := hex.EncodeToString(hashBytes[:])
|
||||
fileCid, err := cid.EncodeHashSimple(hashBytes)
|
||||
fileCid, err := cid.EncodeHashSimple(hashBytes, uint64(meta.Size))
|
||||
|
||||
if internalError(ctx, err) {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue