diff options
author | Julio Capote <jcapote@gmail.com> | 2022-12-19 00:29:19 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2022-12-19 00:29:19 +0000 |
commit | 2ee94a66d89de9eb0461f250251af7776aef9976 (patch) | |
tree | 9cb4a3800c18f4f6b5df84d6cb0d861ff6ae8afc /registry/registry.go | |
parent | 4f8325f5df55628544f13937975f38c6ef5d17ab (diff) | |
download | communique-2ee94a66d89de9eb0461f250251af7776aef9976.tar.gz |
cleanup
Diffstat (limited to '')
-rw-r--r-- | registry/registry.go | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/registry/registry.go b/registry/registry.go index 936ff54..3f88966 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -2,7 +2,6 @@ package registry import ( "fmt" - "path" "git.capotej.com/capotej/communique/config" "git.capotej.com/capotej/communique/resources" @@ -22,37 +21,40 @@ func NewRegistry(cfg config.Config) *Registry { reg.handlerMap = make(map[string]Handler) for _, v := range cfg.Handlers { // TODO clean up - fqdn := fmt.Sprintf("acct:%s@%s", v.Name, cfg.Domain) - reg.handlerMap[fqdn] = Handler{handlerCfg: v} + fqn := fmt.Sprintf("acct:%s@%s", v.Name, cfg.Domain) + reg.handlerMap[fqn] = Handler{handlerCfg: v} } return ® } -// TODO should probably be getprofilebyname -func (r *Registry) LookupByName(name string) (map[string]interface{}, error) { - fqdn := fmt.Sprintf("acct:%s@%s", name, r.cfg.Domain) - if r.LookupResource(fqdn) == nil { +func (r *Registry) Profile(name string) (map[string]interface{}, error) { + handler := r.findByName(name) + if handler == nil { return nil, nil } - return resources.RenderProfile(name, r.cfg.Domain) + return resources.RenderProfile(handler.handlerCfg.Name, r.cfg.Domain) } -// TODO extract an existsbyname existsbyfqdn from this -func (r *Registry) LookupResource(fqdn string) *resources.WebfingerResource { - handler, ok := r.handlerMap[fqdn] +func (r *Registry) WebfingerResource(fqn string) (*resources.WebfingerResource, error) { + handler := r.findByFQN(fqn) + if handler == nil { + handler = r.findByFQN("acct:" + fqn) + } + if handler == nil { + return nil, nil + } + return resources.RenderWebfingerResource(handler.handlerCfg.Name, r.cfg.Domain) +} + +func (r *Registry) findByFQN(fqn string) *Handler { + handler, ok := r.handlerMap[fqn] if !ok { return nil } - rs := resources.WebfingerResource{ - // TODO clean up - Subject: fmt.Sprintf("acct:%s@%s", handler.handlerCfg.Name, r.cfg.Domain), - Aliases: []string{}, - Links: []resources.Link{{ - Rel: "self", - Href: path.Join("https://", r.cfg.Domain, "actors", handler.handlerCfg.Name), - Type: "application/activity+json", - }}, - } - return &rs + return &handler +} +func (r *Registry) findByName(name string) *Handler { + fqn := fmt.Sprintf("acct:%s@%s", name, r.cfg.Domain) + return r.findByFQN(fqn) } |