feat: implement GET /s5/registry
This commit is contained in:
parent
1fcd7fdfdc
commit
cde3f90d2d
|
@ -47,5 +47,8 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand
|
||||||
|
|
||||||
// Debug API
|
// Debug API
|
||||||
"/s5/debug/download_urls/:cid": s5.AuthMiddleware(h.DebugDownloadUrls, portal),
|
"/s5/debug/download_urls/:cid": s5.AuthMiddleware(h.DebugDownloadUrls, portal),
|
||||||
|
|
||||||
|
//Registry API
|
||||||
|
"GET /s5/registry": s5.AuthMiddleware(h.RegistryQuery, portal),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -942,6 +942,36 @@ func (h *HttpHandler) DebugDownloadUrls(jc jape.Context) {
|
||||||
_, _ = jc.ResponseWriter.Write([]byte(strings.Join(output, "\n")))
|
_, _ = jc.ResponseWriter.Write([]byte(strings.Join(output, "\n")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HttpHandler) RegistryQuery(jc jape.Context) {
|
||||||
|
var pk string
|
||||||
|
|
||||||
|
if jc.DecodeForm("pk", &pk) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pkBytes, err := base64.RawURLEncoding.DecodeString(pk)
|
||||||
|
if jc.Check("error decoding pk", err) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
entry, err := h.getNode().Services().Registry().Get(pkBytes)
|
||||||
|
if jc.Check("error getting registry entry", err) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if entry == nil {
|
||||||
|
jc.ResponseWriter.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
jc.Encode(&RegistryQueryResponse{
|
||||||
|
Pk: base64.RawURLEncoding.EncodeToString(entry.PK()),
|
||||||
|
Revision: entry.Revision(),
|
||||||
|
Data: base64.RawURLEncoding.EncodeToString(entry.Data()),
|
||||||
|
Signature: base64.RawURLEncoding.EncodeToString(entry.Signature()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) getNode() s5interfaces.Node {
|
func (h *HttpHandler) getNode() s5interfaces.Node {
|
||||||
proto, _ := h.portal.ProtocolRegistry().Get("s5")
|
proto, _ := h.portal.ProtocolRegistry().Get("s5")
|
||||||
protoInstance := proto.(*protocols.S5Protocol)
|
protoInstance := proto.(*protocols.S5Protocol)
|
||||||
|
|
|
@ -53,3 +53,9 @@ type AccountStatsTotal struct {
|
||||||
type AppUploadResponse struct {
|
type AppUploadResponse struct {
|
||||||
CID string `json:"cid"`
|
CID string `json:"cid"`
|
||||||
}
|
}
|
||||||
|
type RegistryQueryResponse struct {
|
||||||
|
Pk string `json:"pk"`
|
||||||
|
Revision uint64 `json:"revision"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue