Compare commits
No commits in common. "c0df04d7d5309e32348ceecc68eecd64c5e5cba4" and "b104af5e4cd5de06dfde3a397eae3adc1127f112" have entirely different histories.
c0df04d7d5
...
b104af5e4c
17
cid/cid.go
17
cid/cid.go
|
@ -10,11 +10,6 @@ import (
|
||||||
|
|
||||||
var MAGIC_BYTES = []byte{0x26, 0x1f}
|
var MAGIC_BYTES = []byte{0x26, 0x1f}
|
||||||
|
|
||||||
var (
|
|
||||||
ErrMissingEmptySize = errors.New("Missing or empty size")
|
|
||||||
ErrInvalidCIDMagic = errors.New("CID magic bytes missing or invalid")
|
|
||||||
)
|
|
||||||
|
|
||||||
type CID struct {
|
type CID struct {
|
||||||
Hash [32]byte
|
Hash [32]byte
|
||||||
Size uint64
|
Size uint64
|
||||||
|
@ -81,19 +76,13 @@ func maybeDecode(cid string) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(data[0:len(MAGIC_BYTES)], MAGIC_BYTES) != 0 {
|
if bytes.Compare(data[0:len(MAGIC_BYTES)], MAGIC_BYTES) != 0 {
|
||||||
return nil, ErrInvalidCIDMagic
|
return nil, errors.New("CID magic bytes missing or invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
sizeBytes := data[len(MAGIC_BYTES)+32:]
|
size := binary.LittleEndian.Uint64(data[len(MAGIC_BYTES)+32:])
|
||||||
|
|
||||||
if len(sizeBytes) == 0 {
|
|
||||||
return nil, ErrMissingEmptySize
|
|
||||||
}
|
|
||||||
|
|
||||||
size := binary.LittleEndian.Uint64(sizeBytes)
|
|
||||||
|
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
return nil, ErrMissingEmptySize
|
return nil, errors.New("missing or empty size")
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
|
|
|
@ -130,7 +130,7 @@ func (f *FilesController) GetStatusBy(cidString string) {
|
||||||
statusCode = "uploading"
|
statusCode = "uploading"
|
||||||
break
|
break
|
||||||
case files.STATUS_NOT_FOUND:
|
case files.STATUS_NOT_FOUND:
|
||||||
statusCode = "not_found"
|
statusCode = "uploading"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue