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

add public /keys/{user} endpoint

fetch keys like gh.com/user.keys

Changed files
+41 -4
appview
state
knotserver
+31 -3
appview/state/state.go
···
}
func (s *State) Keys(w http.ResponseWriter, r *http.Request) {
+
user := chi.URLParam(r, "user")
+
user = strings.TrimPrefix(user, "@")
+
+
if user == "" {
+
w.Write([]byte("not found"))
+
return
+
}
+
+
id, err := auth.ResolveIdent(r.Context(), user)
+
if err != nil {
+
w.Write([]byte("not found"))
+
return
+
}
+
+
pubKeys, err := s.db.GetPublicKeys(id.DID.String())
+
if err != nil {
+
w.Write([]byte("not found"))
+
return
+
}
+
+
for _, k := range pubKeys {
+
w.Write([]byte(fmt.Sprintln(k.Key)))
+
}
+
}
+
+
func (s *State) SettingsKeys(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
w.Write([]byte("unimplemented"))
···
// r.Post("/import", s.ImportRepo)
})
-
r.Group(func(r chi.Router) {
+
r.Route("/settings", func(r chi.Router) {
r.Use(AuthMiddleware(s))
-
r.Get("/settings", s.Settings)
-
r.Put("/settings/keys", s.Keys)
+
r.Get("/", s.Settings)
+
r.Put("/keys", s.SettingsKeys)
})
+
+
r.Get("/keys/{user}", s.Keys)
return r
}
+10 -1
knotserver/routes.go
···
did := data.Did
name := data.Name
-
repoPath := filepath.Join(h.c.Repo.ScanPath, did, name)
+
relativeRepoPath := filepath.Join(did, name)
+
repoPath := filepath.Join(h.c.Repo.ScanPath, relativeRepoPath)
err := git.InitBare(repoPath)
+
if err != nil {
+
log.Println(err)
+
writeError(w, err.Error(), http.StatusInternalServerError)
+
return
+
}
+
+
// add perms for this user to access the repo
+
err = h.e.AddRepo(did, ThisServer, relativeRepoPath)
if err != nil {
log.Println(err)
writeError(w, err.Error(), http.StatusInternalServerError)