MCPcopy Index your code
hub / github.com/Preloading/TwitterAPIBridge / UpdateProfile

Function UpdateProfile

twitterv1/account.go:102–145  ·  view source on GitHub ↗
(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

100}
101
102func UpdateProfile(c *fiber.Ctx) error {
103 // auth
104 my_did, pds, _, oauthToken, err := GetAuthFromReq(c)
105 if err != nil {
106 return MissingAuth(c, err)
107 }
108
109 // Lock the mutex for this user
110 userMutex := getUserMutex(*my_did)
111 userMutex.Lock()
112 defer userMutex.Unlock()
113
114 description := c.FormValue("description")
115 name := c.FormValue("name")
116 // These don't exist in bluesky.
117 // location := c.FormValue("location")
118 // url := c.FormValue("url")
119
120 // some quality of life features
121 description = strings.ReplaceAll(description, "\\n", "\n")
122
123 oldProfile, err := blueskyapi.GetRecord(*pds, "app.bsky.actor.profile", *my_did, "self")
124 if err != nil {
125 return HandleBlueskyError(c, err.Error(), "com.atproto.repo.getRecord", UpdateProfile)
126 }
127
128 oldProfile.Value.DisplayName = name
129 oldProfile.Value.Description = description
130
131 if err := blueskyapi.UpdateRecord(*pds, *oauthToken, "app.bsky.actor.profile", *my_did, "self", oldProfile.CID, oldProfile.Value); err != nil {
132 return HandleBlueskyError(c, err.Error(), "com.atproto.repo.putRecord", UpdateProfile)
133 }
134
135 user, err := blueskyapi.GetUserInfo(*pds, *oauthToken, *my_did, true)
136 if err != nil {
137 fmt.Println("Error:", err)
138 return HandleBlueskyError(c, err.Error(), "app.bsky.actor.getProfile", UpdateProfile)
139 }
140
141 user.Description = description
142 user.Name = name
143
144 return EncodeAndSend(c, user)
145}
146
147func UpdateProfilePicture(c *fiber.Ctx) error {
148 // auth

Callers

nothing calls this directly

Calls 5

GetAuthFromReqFunction · 0.85
MissingAuthFunction · 0.85
getUserMutexFunction · 0.85
HandleBlueskyErrorFunction · 0.85
EncodeAndSendFunction · 0.85

Tested by

no test coverage detected