tiny 88x31 lexicon for atproto
0
fork

Configure Feed

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

fix uri for buttonviewauth

+49
+1
db/lexicon.go
··· 127 127 if err != nil { 128 128 return nil, err 129 129 } 130 + btn.URI = uri 130 131 return &btn, nil 131 132 } 132 133
+1
handler/handler.go
··· 37 37 mux.HandleFunc("GET /upload", h.oauthMiddleware(getupload)) 38 38 mux.HandleFunc("POST /upload", h.oauthMiddleware(h.upload)) 39 39 mux.HandleFunc("POST /like", h.oauthMiddleware(h.like)) 40 + mux.HandleFunc("DELETE /like", h.oauthMiddleware(h.unlike)) 40 41 mux.HandleFunc("GET /button", h.oauthMiddleware(h.getbutton)) 41 42 mux.HandleFunc("GET /xrpc/store.88x31.getButton", h.WithCORS(h.getButton)) 42 43 mux.HandleFunc("GET /xrpc/store.88x31.getButtons", h.WithCORS(h.getButtons))
+47
handler/upload.go
··· 62 62 http.Redirect(w, r, fmt.Sprintf("/button?uri=%s", uri), http.StatusCreated) 63 63 } 64 64 65 + func (h *Handler) unlike(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 66 + if cs == nil { 67 + http.Error(w, "like requires auth", http.StatusUnauthorized) 68 + return 69 + } 70 + err := r.ParseForm() 71 + if err != nil { 72 + http.Error(w, "form failed to parse", http.StatusBadRequest) 73 + return 74 + } 75 + uri := r.FormValue("uri") 76 + if uri == "" { 77 + http.Error(w, "must provide uri, don't tamper with form", http.StatusBadRequest) 78 + return 79 + } 80 + cid := r.FormValue("cid") 81 + if cid == "" { 82 + http.Error(w, "must provide a cid, don't tamper with form", http.StatusBadRequest) 83 + return 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()) 91 + if err != nil { 92 + log.Println(err) 93 + http.Error(w, "error creating post", http.StatusInternalServerError) 94 + return 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()) 104 + if err != nil { 105 + log.Println(err) 106 + http.Error(w, "error storing like", http.StatusInternalServerError) 107 + return 108 + } 109 + http.Redirect(w, r, fmt.Sprintf("/button?uri=%s", uri), http.StatusCreated) 110 + } 111 + 65 112 func (h *Handler) upload(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 66 113 if cs == nil { 67 114 http.Error(w, "upload requires auth", http.StatusUnauthorized)