forked from tangled.org/core
this repo has no description

introduce capabilities to knotserver

Changed files
+33
appview
state
knotserver
+14
appview/state/signer.go
···
return us.client.Do(req)
}
···
return us.client.Do(req)
}
+
+
func (us *UnsignedClient) Capabilities(ownerDid, repoName string) (*http.Response, error) {
+
const (
+
Method = "GET"
+
Endpoint = "/capabilities"
+
)
+
+
req, err := us.newRequest(Method, Endpoint, nil)
+
if err != nil {
+
return nil, err
+
}
+
+
return us.client.Do(req)
+
}
+1
knotserver/handler.go
···
}
r.Get("/", h.Index)
r.Get("/version", h.Version)
r.Route("/{did}", func(r chi.Router) {
// Repo routes
···
}
r.Get("/", h.Index)
+
r.Get("/capabilities", h.Capabilities)
r.Get("/version", h.Version)
r.Route("/{did}", func(r chi.Router) {
// Repo routes
+18
knotserver/routes.go
···
w.Write([]byte("This is a knot server. More info at https://tangled.sh"))
}
func (h *Handle) RepoIndex(w http.ResponseWriter, r *http.Request) {
path, _ := securejoin.SecureJoin(h.c.Repo.ScanPath, didPath(r))
l := h.l.With("path", path, "handler", "RepoIndex")
···
w.Write([]byte("This is a knot server. More info at https://tangled.sh"))
}
+
func (h *Handle) Capabilities(w http.ResponseWriter, r *http.Request) {
+
w.Header().Set("Content-Type", "application/json")
+
+
capabilities := map[string]any{
+
"pull_requests": map[string]any{
+
"patch_submissions": true,
+
},
+
}
+
+
jsonData, err := json.Marshal(capabilities)
+
if err != nil {
+
http.Error(w, "Failed to serialize JSON", http.StatusInternalServerError)
+
return
+
}
+
+
w.Write(jsonData)
+
}
+
func (h *Handle) RepoIndex(w http.ResponseWriter, r *http.Request) {
path, _ := securejoin.SecureJoin(h.c.Repo.ScanPath, didPath(r))
l := h.l.With("path", path, "handler", "RepoIndex")