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 logger := s.logger.With("name", "handleServerResolveHandle")
14
15 type Resp struct {
16 Did string `json:"did"`
17 }
18
19 handle := e.QueryParam("handle")
20
21 if handle == "" {
22 return helpers.InputError(e, to.StringPtr("Handle must be supplied in request."))
23 }
24
25 parsed, err := syntax.ParseHandle(handle)
26 if err != nil {
27 return helpers.InputError(e, to.StringPtr("Invalid handle."))
28 }
29
30 ctx := context.WithValue(e.Request().Context(), "skip-cache", true)
31 did, err := s.passport.ResolveHandle(ctx, parsed.String())
32 if err != nil {
33 logger.Error("error resolving handle", "error", err)
34 return helpers.ServerError(e, nil)
35 }
36
37 return e.JSON(200, Resp{
38 Did: did,
39 })
40}