Monorepo for Tangled
1package xrpc
2
3import (
4 "database/sql"
5 "errors"
6 "net/http"
7 "strings"
8
9 "tangled.org/core/api/tangled"
10 xrpcerr "tangled.org/core/xrpc/errors"
11)
12
13func (x *Xrpc) ResolveAtUri(w http.ResponseWriter, r *http.Request) {
14 atUri := r.URL.Query().Get("atUri")
15 if atUri == "" || !strings.HasPrefix(atUri, "at://") {
16 writeError(w, xrpcerr.NewXrpcError(
17 xrpcerr.WithTag("InvalidRequest"),
18 xrpcerr.WithMessage("missing or invalid atUri parameter"),
19 ), http.StatusBadRequest)
20 return
21 }
22
23 repoDid, err := x.Db.ResolveAtUri(atUri)
24 if errors.Is(err, sql.ErrNoRows) {
25 writeError(w, xrpcerr.NewXrpcError(
26 xrpcerr.WithTag("NotFound"),
27 xrpcerr.WithMessage("no repo DID found for the given at-uri"),
28 ), http.StatusNotFound)
29 return
30 }
31 if err != nil {
32 writeError(w, xrpcerr.NewXrpcError(
33 xrpcerr.WithTag("InternalError"),
34 xrpcerr.WithMessage("failed to resolve at-uri"),
35 ), http.StatusInternalServerError)
36 return
37 }
38
39 writeJson(w, tangled.RepoResolveAtUri_Output{Did: repoDid})
40}