tiny 88x31 lexicon for atproto
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

beep beep beep

+34 -17
+7
db/lexicon.go
··· 204 204 `, tlr.URI, tlr.SubjectURI, tlr.SubjectCID, tlr.DID, tlr.CID, tlr.CreatedAt) 205 205 return err 206 206 } 207 + 208 + func (s *Store) DeleteLike(uri string, ctx context.Context) error { 209 + _, err := s.pool.Exec(ctx, ` 210 + DELETE FROM likes WHERE uri = $1 211 + `, uri) 212 + return err 213 + }
+9 -16
handler/upload.go
··· 64 64 65 65 func (h *Handler) unlike(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 66 66 if cs == nil { 67 - http.Error(w, "like requires auth", http.StatusUnauthorized) 67 + http.Error(w, "unlike requires auth", http.StatusUnauthorized) 68 68 return 69 69 } 70 70 err := r.ParseForm() ··· 82 82 http.Error(w, "must provide a cid, don't tamper with form", http.StatusBadRequest) 83 83 return 84 84 } 85 - var llr lex.LikeRecord 86 - lls := lex.LikeSubject{URI: uri, CID: cid} 87 - llr.Subject = lls 88 - nowsyn := syntax.DatetimeNow() 89 - llr.CreatedAt = nowsyn.String() 90 - luri, lcid, err := myoauth.CreateLike(cs, &llr, r.Context()) 85 + 86 + aturi, err := syntax.ParseATURI(uri) 87 + if err != nil { 88 + http.Error(w, "uri doesn't parse, don't tamper with form", http.StatusBadRequest) 89 + } 90 + err = myoauth.DeleteLike(cs, aturi.RecordKey().String(), cid, r.Context()) 91 91 if err != nil { 92 92 log.Println(err) 93 - http.Error(w, "error creating post", http.StatusInternalServerError) 93 + http.Error(w, "error deleting like", http.StatusInternalServerError) 94 94 return 95 95 } 96 - var like types.Like 97 - like.CID = lcid 98 - like.URI = luri 99 - like.CreatedAt = nowsyn.Time() 100 - like.SubjectCID = cid 101 - like.SubjectURI = uri 102 - like.DID = cs.Data.AccountDID.String() 103 - err = h.db.StoreLike(&like, r.Context()) 96 + err = h.db.DeleteLike(uri, r.Context()) 104 97 if err != nil { 105 98 log.Println(err) 106 99 http.Error(w, "error storing like", http.StatusInternalServerError)
+18 -1
oauth/client.go
··· 77 77 var out atproto.RepoCreateRecord_Output 78 78 err = c.Post(ctx, "com.atproto.repo.createRecord", body, &out) 79 79 if err != nil { 80 - err = errors.New("oops! failed to create a channel: " + err.Error()) 80 + err = errors.New("oops! failed to create a like: " + err.Error()) 81 81 return 82 82 } 83 83 uri = out.Uri 84 84 cid = out.Cid 85 85 return 86 86 } 87 + 88 + func DeleteLike(cs *oauth.ClientSession, rkey string, cid string, ctx context.Context) error { 89 + c := cs.APIClient() 90 + body := map[string]any{ 91 + "collection": "store.88x31.like", 92 + "repo": *c.AccountDID, 93 + "rkey": rkey, 94 + "swapRecord": cid, 95 + } 96 + var out atproto.RepoDeleteRecord_Output 97 + err := c.Post(ctx, "com.atproto.repo.deleteRecord", body, &out) 98 + if err != nil { 99 + err = errors.New("oops! failed to delete a like: " + err.Error()) 100 + return err 101 + } 102 + return nil 103 + }