diff options
Diffstat (limited to 'registry/registry.go')
-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) } |