tiny 88x31 lexicon for atproto

Add title text

+73 -7
+4
handler/upload.go
··· 120 120 return 121 121 } 122 122 alt := r.FormValue("alt") 123 + title := r.FormValue("title") 123 124 href := r.FormValue("href") 124 125 125 126 file, fheader, err := r.FormFile("button") ··· 146 147 lbr.Blob = *blob 147 148 if alt != "" { 148 149 lbr.Alt = &alt 150 + } 151 + if title != "" { 152 + lbr.Title = &title 149 153 } 150 154 if href != "" { 151 155 lbr.Href = &href
+58 -1
lex/lexicons_cbor.go
··· 25 25 } 26 26 27 27 cw := cbg.NewCborWriter(w) 28 - fieldCount := 5 28 + fieldCount := 6 29 29 30 30 if t.Href == nil { 31 + fieldCount-- 32 + } 33 + 34 + if t.Title == nil { 31 35 fieldCount-- 32 36 } 33 37 ··· 138 142 return err 139 143 } 140 144 145 + // t.Title (string) (string) 146 + if t.Title != nil { 147 + 148 + if len("title") > 8192 { 149 + return xerrors.Errorf("Value in field \"title\" was too long") 150 + } 151 + 152 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("title"))); err != nil { 153 + return err 154 + } 155 + if _, err := cw.WriteString(string("title")); err != nil { 156 + return err 157 + } 158 + 159 + if t.Title == nil { 160 + if _, err := cw.Write(cbg.CborNull); err != nil { 161 + return err 162 + } 163 + } else { 164 + if len(*t.Title) > 8192 { 165 + return xerrors.Errorf("Value in field t.Title was too long") 166 + } 167 + 168 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Title))); err != nil { 169 + return err 170 + } 171 + if _, err := cw.WriteString(string(*t.Title)); err != nil { 172 + return err 173 + } 174 + } 175 + } 176 + 141 177 // t.PostedAt (string) (string) 142 178 if len("omitEmpty") > 8192 { 143 179 return xerrors.Errorf("Value in field \"omitEmpty\" was too long") ··· 266 302 } 267 303 268 304 t.LexiconTypeID = string(sval) 305 + } 306 + // t.Title (string) (string) 307 + case "title": 308 + 309 + { 310 + b, err := cr.ReadByte() 311 + if err != nil { 312 + return err 313 + } 314 + if b != cbg.CborNull[0] { 315 + if err := cr.UnreadByte(); err != nil { 316 + return err 317 + } 318 + 319 + sval, err := cbg.ReadStringWithMax(cr, 8192) 320 + if err != nil { 321 + return err 322 + } 323 + 324 + t.Title = (*string)(&sval) 325 + } 269 326 } 270 327 // t.PostedAt (string) (string) 271 328 case "omitEmpty":
+1
lex/types.go
··· 10 10 type ButtonRecord struct { 11 11 LexiconTypeID string `json:"$type,const=org.xcvr.actor.profile" cborgen:"$type,const=org.xcvr.actor.profile"` 12 12 Href *string `json:"href,omitempty" cborgen:"href,omitempty"` 13 + Title *string `json:"title,omitempty" cborgen:"title,omitempty"` 13 14 Alt *string `json:"alt,omitempty" cborgen:"alt,omitempty"` 14 15 Blob util.BlobSchema `json:"blob" cborgen:"blob"` 15 16 PostedAt string `json:"postedAt,omitempty" cborgen:"postedAt,omitEmpty" `
+1 -1
tmpl/partial/buttonpart.html
··· 1 1 {{define "buttonpart"}} 2 2 <a href="{{.HREF}}"> 3 - <img src="/xrpc/store.88x31.getButton?uri={{.URI}}" alt="{{.Alt}}" style="display: block"/> 3 + <img src="/xrpc/store.88x31.getButton?uri={{.URI}}" alt="{{.Alt}}" title="{{.Title}}" style="display: block"/> 4 4 </a> 5 5 {{end}}
+1
tmpl/upload.html
··· 2 2 <form action="/upload" method="POST" enctype="multipart/form-data"> 3 3 <div><input type="file" name="button" value="select file" accept="image/png, image/jpg, image/gif"/></div> 4 4 <div><input type="text" name="alt" placeholder="alt text"/></div> 5 + <div><input type="text" name="title" placeholder="title text"/></div> 5 6 <div><input type="text" name="href" placeholder="link"/></div> 6 7 <div><input type="submit" value="upload"/></div> 7 8 </form>
+8 -5
types/lexicon.go
··· 10 10 BlobCID string 11 11 BlobMIME string 12 12 Alt *string 13 + Title *string 13 14 HREF *string 14 15 CID string 15 16 PostedAt time.Time ··· 17 18 } 18 19 19 20 type ButtonView struct { 20 - URI string `json:"uri"` 21 - CID string `json:"cid"` 22 - DID string `json:"did"` 23 - Alt *string `json:"alt,omitempty"` 24 - HREF *string `json:"href,omitempty"` 21 + URI string `json:"uri"` 22 + CID string `json:"cid"` 23 + DID string `json:"did"` 24 + Alt *string `json:"alt,omitempty"` 25 + Title *string `json:"title,omitempty"` 26 + HREF *string `json:"href,omitempty"` 25 27 } 26 28 27 29 type ButtonViewAuth struct { ··· 29 31 CID string `json:"cid"` 30 32 DID string `json:"did"` 31 33 Alt *string `json:"alt,omitempty"` 34 + Title *string `json:"title,omitempty"` 32 35 HREF *string `json:"href,omitempty"` 33 36 Liked bool `json:"liked"` 34 37 }