feat: add proof download support to download endpoint
This commit is contained in:
parent
850b575e1c
commit
0c00e2e7d9
|
@ -1346,6 +1346,12 @@ func (h *HttpHandler) DownloadFile(jc jape.Context) {
|
|||
}
|
||||
|
||||
var hashBytes []byte
|
||||
isProof := false
|
||||
|
||||
if strings.HasSuffix(cid, ".bao") {
|
||||
isProof = true
|
||||
cid = strings.TrimSuffix(cid, ".bao")
|
||||
}
|
||||
|
||||
cidDecoded, err := encoding.CIDFromString(cid)
|
||||
|
||||
|
@ -1358,7 +1364,6 @@ func (h *HttpHandler) DownloadFile(jc jape.Context) {
|
|||
|
||||
hashBytes = hashDecoded.HashBytes()
|
||||
} else {
|
||||
|
||||
hashBytes = cidDecoded.Hash.HashBytes()
|
||||
}
|
||||
|
||||
|
@ -1376,6 +1381,18 @@ func (h *HttpHandler) DownloadFile(jc jape.Context) {
|
|||
}
|
||||
}(file)
|
||||
|
||||
if isProof {
|
||||
proof, err := file.Proof()
|
||||
|
||||
if jc.Check("error getting proof", err) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
jc.ResponseWriter.Header().Set("Content-Type", "application/octet-stream")
|
||||
http.ServeContent(jc.ResponseWriter, jc.Request, fmt.Sprintf("%.bao", file.Name()), file.Modtime(), bytes.NewReader(proof))
|
||||
return
|
||||
}
|
||||
|
||||
jc.ResponseWriter.Header().Set("Content-Type", file.Mime())
|
||||
|
||||
http.ServeContent(jc.ResponseWriter, jc.Request, file.Name(), file.Modtime(), file)
|
||||
|
|
|
@ -183,7 +183,6 @@ func getRoutes(s *S5API) map[string]jape.Handler {
|
|||
// Download API
|
||||
"GET /s5/blob/:cid": middleware.ApplyMiddlewares(s.httpHandler.DownloadBlob, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||
"GET /s5/metadata/:cid": s.httpHandler.DownloadMetadata,
|
||||
// "GET /s5/download/:cid": middleware.ApplyMiddlewares(s.httpHandler.DownloadFile, middleware.AuthMiddleware(portal)),
|
||||
"GET /s5/download/:cid": middleware.ApplyMiddlewares(s.httpHandler.DownloadFile, cors.Default().Handler),
|
||||
|
||||
// Pins API
|
||||
|
|
Loading…
Reference in New Issue