fix: handle both cid and base64url hash

This commit is contained in:
Derrick Hammer 2024-01-24 17:15:21 -05:00
parent 562742fd8e
commit 95b57cffc0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 3 deletions

View File

@ -1286,12 +1286,23 @@ func (h *HttpHandler) DownloadFile(jc jape.Context) {
return
}
var hashBytes []byte
cidDecoded, err := encoding.CIDFromString(cid)
if jc.Check("error decoding cid", err) != nil {
return
if err != nil {
hashDecoded, err := encoding.MultihashFromBase64Url(cid)
if jc.Check("error decoding as cid or hash", err) != nil {
return
}
hashBytes = hashDecoded.HashBytes()
}
file, fileSize, err := h.portal.Storage().GetFile(cidDecoded.Hash.HashBytes())
hashBytes = cidDecoded.Hash.HashBytes()
file, fileSize, err := h.portal.Storage().GetFile(hashBytes)
if jc.Check("error getting file", err) != nil {
return
}