feat: implement /s5/metadata/:cid
This commit is contained in:
parent
510a57162c
commit
f957ef5d78
|
@ -42,7 +42,8 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand
|
|||
"POST /s5/upload/directory": s5.AuthMiddleware(h.DirectoryUpload, portal),
|
||||
|
||||
// Download API
|
||||
"GET /s5/blob/:cid": s5.AuthMiddleware(h.DownloadBlob, portal),
|
||||
"GET /s5/blob/:cid": s5.AuthMiddleware(h.DownloadBlob, portal),
|
||||
"GET /s5/metadata/:cid": s5.AuthMiddleware(h.DownloadMetadata, portal),
|
||||
|
||||
// Pins API
|
||||
"POST /s5/pin/:cid": s5.AuthMiddleware(h.AccountPin, portal),
|
||||
|
|
|
@ -1238,6 +1238,44 @@ func (h *HttpHandler) DebugStorageLocations(jc jape.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
func (h *HttpHandler) DownloadMetadata(jc jape.Context) {
|
||||
var cid string
|
||||
|
||||
if jc.DecodeParam("cid", &cid) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
cidDecoded, err := encoding.CIDFromString(cid)
|
||||
if jc.Check("error decoding cid", err) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch cidDecoded.Type {
|
||||
case types.CIDTypeRaw:
|
||||
_ = jc.Error(errors.New("Raw CIDs do not have metadata"), http.StatusBadRequest)
|
||||
return
|
||||
|
||||
case types.CIDTypeResolver:
|
||||
_ = jc.Error(errors.New("Resolver CIDs not yet supported"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
meta, err := h.getNode().GetMetadataByCID(cidDecoded)
|
||||
|
||||
if jc.Check("error getting metadata", err) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if cidDecoded.Type != types.CIDTypeBridge {
|
||||
jc.ResponseWriter.Header().Set("Cache-Control", "public, max-age=31536000")
|
||||
} else {
|
||||
jc.ResponseWriter.Header().Set("Cache-Control", "public, max-age=60")
|
||||
}
|
||||
|
||||
jc.Encode(&meta)
|
||||
|
||||
}
|
||||
|
||||
func setAuthCookie(jwt string, jc jape.Context) {
|
||||
authCookie := http.Cookie{
|
||||
Name: "s5-auth-token",
|
||||
|
|
Loading…
Reference in New Issue