Compare commits
2 Commits
b104af5e4c
...
c0df04d7d5
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | c0df04d7d5 | |
Derrick Hammer | 385a51e504 |
17
cid/cid.go
17
cid/cid.go
|
@ -10,6 +10,11 @@ import (
|
|||
|
||||
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 {
|
||||
Hash [32]byte
|
||||
Size uint64
|
||||
|
@ -76,13 +81,19 @@ func maybeDecode(cid string) ([]byte, error) {
|
|||
}
|
||||
|
||||
if bytes.Compare(data[0:len(MAGIC_BYTES)], MAGIC_BYTES) != 0 {
|
||||
return nil, errors.New("CID magic bytes missing or invalid")
|
||||
return nil, ErrInvalidCIDMagic
|
||||
}
|
||||
|
||||
size := binary.LittleEndian.Uint64(data[len(MAGIC_BYTES)+32:])
|
||||
sizeBytes := data[len(MAGIC_BYTES)+32:]
|
||||
|
||||
if len(sizeBytes) == 0 {
|
||||
return nil, ErrMissingEmptySize
|
||||
}
|
||||
|
||||
size := binary.LittleEndian.Uint64(sizeBytes)
|
||||
|
||||
if size == 0 {
|
||||
return nil, errors.New("missing or empty size")
|
||||
return nil, ErrMissingEmptySize
|
||||
}
|
||||
|
||||
return data, nil
|
||||
|
|
|
@ -130,7 +130,7 @@ func (f *FilesController) GetStatusBy(cidString string) {
|
|||
statusCode = "uploading"
|
||||
break
|
||||
case files.STATUS_NOT_FOUND:
|
||||
statusCode = "uploading"
|
||||
statusCode = "not_found"
|
||||
break
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue