feat: implement /s5/blob/:cid
This commit is contained in:
parent
dfd03673c9
commit
0c88e80a66
|
@ -41,6 +41,9 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand
|
||||||
"POST /s5/upload": s5.AuthMiddleware(h.SmallFileUpload, portal),
|
"POST /s5/upload": s5.AuthMiddleware(h.SmallFileUpload, portal),
|
||||||
"POST /s5/upload/directory": s5.AuthMiddleware(h.DirectoryUpload, portal),
|
"POST /s5/upload/directory": s5.AuthMiddleware(h.DirectoryUpload, portal),
|
||||||
|
|
||||||
|
// Download API
|
||||||
|
"GET /s5/blob/:cid": s5.AuthMiddleware(h.DownloadBlob, portal),
|
||||||
|
|
||||||
// Pins API
|
// Pins API
|
||||||
"POST /s5/pin/:cid": s5.AuthMiddleware(h.AccountPin, portal),
|
"POST /s5/pin/:cid": s5.AuthMiddleware(h.AccountPin, portal),
|
||||||
"DELETE /s5/delete/:cid": s5.AuthMiddleware(h.AccountPinDelete, portal),
|
"DELETE /s5/delete/:cid": s5.AuthMiddleware(h.AccountPinDelete, portal),
|
||||||
|
|
|
@ -1107,6 +1107,36 @@ func (h *HttpHandler) getNode() s5interfaces.Node {
|
||||||
return protoInstance.Node()
|
return protoInstance.Node()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HttpHandler) DownloadBlob(jc jape.Context) {
|
||||||
|
var cid string
|
||||||
|
|
||||||
|
if jc.DecodeParam("cid", &cid) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cid = strings.Split(cid, ".")[0]
|
||||||
|
|
||||||
|
cidDecoded, err := encoding.CIDFromString(cid)
|
||||||
|
if jc.Check("error decoding cid", err) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dlUriProvider := s5storage.NewStorageLocationProvider(h.getNode(), &cidDecoded.Hash, types.StorageLocationTypeFull, types.StorageLocationTypeFile, types.StorageLocationTypeBridge)
|
||||||
|
|
||||||
|
err = dlUriProvider.Start()
|
||||||
|
|
||||||
|
if jc.Check("error starting search", err) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next, err := dlUriProvider.Next()
|
||||||
|
if jc.Check("error fetching blob", err) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(jc.ResponseWriter, jc.Request, next.Location().BytesURL(), http.StatusFound)
|
||||||
|
}
|
||||||
|
|
||||||
func setAuthCookie(jwt string, jc jape.Context) {
|
func setAuthCookie(jwt string, jc jape.Context) {
|
||||||
authCookie := http.Cookie{
|
authCookie := http.Cookie{
|
||||||
Name: "s5-auth-token",
|
Name: "s5-auth-token",
|
||||||
|
|
Loading…
Reference in New Issue