1package server
2
3import (
4 "context"
5
6 "github.com/Azure/go-autorest/autorest/to"
7 "github.com/bluesky-social/indigo/atproto/syntax"
8 "github.com/haileyok/cocoon/internal/helpers"
9 "github.com/labstack/echo/v4"
10)
11
12func (s *Server) handleResolveHandle(e echo.Context) error {
13 type Resp struct {
14 Did string `json:"did"`
15 }
16
17 handle := e.QueryParam("handle")
18
19 if handle == "" {
20 return helpers.InputError(e, to.StringPtr("Handle must be supplied in request."))
21 }
22
23 parsed, err := syntax.ParseHandle(handle)
24 if err != nil {
25 return helpers.InputError(e, to.StringPtr("Invalid handle."))
26 }
27
28 ctx := context.WithValue(e.Request().Context(), "skip-cache", true)
29 did, err := s.passport.ResolveHandle(ctx, parsed.String())
30 if err != nil {
31 s.logger.Error("error resolving handle", "error", err)
32 return helpers.ServerError(e, nil)
33 }
34
35 return e.JSON(200, Resp{
36 Did: did,
37 })
38}