tangled
alpha
login
or
join now
moth11.net
/
88x31
0
fork
atom
tiny 88x31 lexicon for atproto
0
fork
atom
overview
issues
pulls
pipelines
Add title text
moth11.net
1 month ago
db6ee2ef
97db1d16
+73
-7
6 changed files
expand all
collapse all
unified
split
handler
upload.go
lex
lexicons_cbor.go
types.go
tmpl
partial
buttonpart.html
upload.html
types
lexicon.go
+4
handler/upload.go
···
120
120
return
121
121
}
122
122
alt := r.FormValue("alt")
123
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
150
+
}
151
151
+
if title != "" {
152
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
28
-
fieldCount := 5
28
28
+
fieldCount := 6
29
29
30
30
if t.Href == nil {
31
31
+
fieldCount--
32
32
+
}
33
33
+
34
34
+
if t.Title == nil {
31
35
fieldCount--
32
36
}
33
37
···
138
142
return err
139
143
}
140
144
145
145
+
// t.Title (string) (string)
146
146
+
if t.Title != nil {
147
147
+
148
148
+
if len("title") > 8192 {
149
149
+
return xerrors.Errorf("Value in field \"title\" was too long")
150
150
+
}
151
151
+
152
152
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("title"))); err != nil {
153
153
+
return err
154
154
+
}
155
155
+
if _, err := cw.WriteString(string("title")); err != nil {
156
156
+
return err
157
157
+
}
158
158
+
159
159
+
if t.Title == nil {
160
160
+
if _, err := cw.Write(cbg.CborNull); err != nil {
161
161
+
return err
162
162
+
}
163
163
+
} else {
164
164
+
if len(*t.Title) > 8192 {
165
165
+
return xerrors.Errorf("Value in field t.Title was too long")
166
166
+
}
167
167
+
168
168
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Title))); err != nil {
169
169
+
return err
170
170
+
}
171
171
+
if _, err := cw.WriteString(string(*t.Title)); err != nil {
172
172
+
return err
173
173
+
}
174
174
+
}
175
175
+
}
176
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
305
+
}
306
306
+
// t.Title (string) (string)
307
307
+
case "title":
308
308
+
309
309
+
{
310
310
+
b, err := cr.ReadByte()
311
311
+
if err != nil {
312
312
+
return err
313
313
+
}
314
314
+
if b != cbg.CborNull[0] {
315
315
+
if err := cr.UnreadByte(); err != nil {
316
316
+
return err
317
317
+
}
318
318
+
319
319
+
sval, err := cbg.ReadStringWithMax(cr, 8192)
320
320
+
if err != nil {
321
321
+
return err
322
322
+
}
323
323
+
324
324
+
t.Title = (*string)(&sval)
325
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
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
3
-
<img src="/xrpc/store.88x31.getButton?uri={{.URI}}" alt="{{.Alt}}" style="display: block"/>
3
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
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
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
20
-
URI string `json:"uri"`
21
21
-
CID string `json:"cid"`
22
22
-
DID string `json:"did"`
23
23
-
Alt *string `json:"alt,omitempty"`
24
24
-
HREF *string `json:"href,omitempty"`
21
21
+
URI string `json:"uri"`
22
22
+
CID string `json:"cid"`
23
23
+
DID string `json:"did"`
24
24
+
Alt *string `json:"alt,omitempty"`
25
25
+
Title *string `json:"title,omitempty"`
26
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
34
+
Title *string `json:"title,omitempty"`
32
35
HREF *string `json:"href,omitempty"`
33
36
Liked bool `json:"liked"`
34
37
}