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 docs
moth11.net
1 month ago
6a003db6
205989ce
+77
-78
2 changed files
expand all
collapse all
unified
split
handler
handler.go
tmpl
embedbase.html
+76
-77
handler/handler.go
···
1
package handler
2
3
import (
4
-
"fmt"
5
"github.com/bluesky-social/indigo/atproto/auth/oauth"
6
"github.com/bluesky-social/indigo/atproto/identity"
7
"github.com/bluesky-social/indigo/atproto/syntax"
···
189
"prefer to use atproto did! i don't locally store handle:did mappings, so if you use a handle, i have to resolve it on the fly, which adds latency",
190
"https://88x31.store/embed/liked-by?handle=moth11.net",
191
},
0
0
0
0
0
0
192
}
193
194
err := lbreferenceT.ExecuteTemplate(w, "base.html", rd)
···
197
}
198
}
199
200
-
func (h *Handler) getbutton(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) {
201
-
if cs != nil {
202
-
h.getbuttonauth(cs, w, r)
203
-
return
204
-
}
205
-
uri := r.URL.Query().Get("uri")
206
-
btn, err := h.db.GetButton(uri, r.Context())
207
-
if err != nil || btn == nil {
208
-
http.Error(w, "not found", http.StatusNotFound)
209
-
return
210
-
}
211
-
type ButtonData struct {
212
-
DID *string
213
-
Title string
214
-
Button types.Button
215
-
}
216
-
var btnd ButtonData
217
-
if btn.Alt != nil {
218
-
btnd.Title = *btn.Alt
219
-
} else {
220
-
btnd.Title = uri
221
-
}
222
-
btnd.Button = *btn
223
-
err = buttonT.ExecuteTemplate(w, "base.html", btnd)
224
-
if err != nil {
225
-
http.Error(w, "error templating", http.StatusInternalServerError)
226
-
}
227
-
}
228
-
229
-
func (h *Handler) getbuttonauth(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) {
230
-
if cs == nil {
231
-
panic("cs must be non nil when i call getbuttonauth")
232
-
}
233
-
did := cs.Data.AccountDID.String()
234
-
uri := r.URL.Query().Get("uri")
235
-
btn, err := h.db.GetButtonAuth(uri, r.Context(), did)
236
-
if err != nil || btn == nil {
237
-
if err != nil {
238
-
log.Println(err)
239
-
}
240
-
http.Error(w, "not found", http.StatusNotFound)
241
-
return
242
-
}
243
-
type ButtonData struct {
244
-
DID *string
245
-
Title string
246
-
Button types.ButtonViewAuth
247
-
}
248
-
var btnd ButtonData
249
-
btnd.DID = &did
250
-
if btn.Alt != nil {
251
-
btnd.Title = *btn.Alt
252
-
} else {
253
-
btnd.Title = uri
254
-
}
255
-
btnd.Button = *btn
256
-
err = buttonT.ExecuteTemplate(w, "base.html", btnd)
257
-
if err != nil {
258
-
log.Println(err)
259
-
http.Error(w, "error templating", http.StatusInternalServerError)
260
-
}
261
-
}
262
-
263
func (h *Handler) getuserlikes(w http.ResponseWriter, r *http.Request) {
264
q := r.URL.Query()
265
did := q.Get("did")
···
270
id, err := identity.DefaultDirectory().LookupHandle(r.Context(), h)
271
if err == nil {
272
did = id.DID.String()
273
-
log.Println(did)
274
-
} else {
275
-
log.Println(err.Error())
276
}
277
-
} else {
278
-
log.Println(err.Error())
279
}
280
}
281
-
bg := q.Get("bg")
282
-
if len(bg) == 6 {
283
-
bg = fmt.Sprintf("#%s", bg)
284
-
} else {
285
-
bg = "white"
286
-
}
287
cursor := q.Get("cursor")
288
var crsr *string
289
if cursor != "" {
···
318
if err != nil {
319
marginbottom = 2
320
}
0
0
0
0
0
321
imageRendering := q.Get("image-rendering")
322
switch imageRendering {
323
case "auto", "smooth", "crisp-edges", "high-quality":
···
332
return
333
}
334
type EmbedData struct {
335
-
Background string
336
Buttons []types.ButtonView
337
Cursor *time.Time
338
Attribute bool
···
345
MarginBottom float64
346
}
347
var ed EmbedData
348
-
ed.Background = bg
349
ed.Buttons = btns
350
ed.Cursor = ncrsr
351
ed.Attribute = attribute != ""
···
357
ed.MarginRight = marginright
358
ed.MarginBottom = marginbottom
359
err = embedT.ExecuteTemplate(w, "embedbase.html", ed)
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
360
if err != nil {
361
log.Println(err)
362
http.Error(w, "error templating", http.StatusInternalServerError)
···
1
package handler
2
3
import (
0
4
"github.com/bluesky-social/indigo/atproto/auth/oauth"
5
"github.com/bluesky-social/indigo/atproto/identity"
6
"github.com/bluesky-social/indigo/atproto/syntax"
···
188
"prefer to use atproto did! i don't locally store handle:did mappings, so if you use a handle, i have to resolve it on the fly, which adds latency",
189
"https://88x31.store/embed/liked-by?handle=moth11.net",
190
},
191
+
{
192
+
"attribute=",
193
+
"non-empty string",
194
+
"any non-empty string for attribute will add a line at the bottom of the generated html linking to 88x31.store. no worries if you prefer the plain look!",
195
+
"https://88x31.store/embed/liked-by?did=did:plc:25z6ogppprfvijcnqo2fsfce&attribute=yes",
196
+
},
197
}
198
199
err := lbreferenceT.ExecuteTemplate(w, "base.html", rd)
···
202
}
203
}
204
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
205
func (h *Handler) getuserlikes(w http.ResponseWriter, r *http.Request) {
206
q := r.URL.Query()
207
did := q.Get("did")
···
212
id, err := identity.DefaultDirectory().LookupHandle(r.Context(), h)
213
if err == nil {
214
did = id.DID.String()
0
0
0
215
}
0
0
216
}
217
}
0
0
0
0
0
0
218
cursor := q.Get("cursor")
219
var crsr *string
220
if cursor != "" {
···
249
if err != nil {
250
marginbottom = 2
251
}
252
+
m := q.Get("margin")
253
+
margin, err := strconv.ParseFloat(m, 64)
254
+
if err != nil {
255
+
margin = 0
256
+
}
257
imageRendering := q.Get("image-rendering")
258
switch imageRendering {
259
case "auto", "smooth", "crisp-edges", "high-quality":
···
268
return
269
}
270
type EmbedData struct {
271
+
Margin float64
272
Buttons []types.ButtonView
273
Cursor *time.Time
274
Attribute bool
···
281
MarginBottom float64
282
}
283
var ed EmbedData
284
+
ed.Margin = margin
285
ed.Buttons = btns
286
ed.Cursor = ncrsr
287
ed.Attribute = attribute != ""
···
293
ed.MarginRight = marginright
294
ed.MarginBottom = marginbottom
295
err = embedT.ExecuteTemplate(w, "embedbase.html", ed)
296
+
if err != nil {
297
+
log.Println(err)
298
+
http.Error(w, "error templating", http.StatusInternalServerError)
299
+
}
300
+
}
301
+
302
+
func (h *Handler) getbutton(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) {
303
+
if cs != nil {
304
+
h.getbuttonauth(cs, w, r)
305
+
return
306
+
}
307
+
uri := r.URL.Query().Get("uri")
308
+
btn, err := h.db.GetButton(uri, r.Context())
309
+
if err != nil || btn == nil {
310
+
http.Error(w, "not found", http.StatusNotFound)
311
+
return
312
+
}
313
+
type ButtonData struct {
314
+
DID *string
315
+
Title string
316
+
Button types.Button
317
+
}
318
+
var btnd ButtonData
319
+
if btn.Alt != nil {
320
+
btnd.Title = *btn.Alt
321
+
} else {
322
+
btnd.Title = uri
323
+
}
324
+
btnd.Button = *btn
325
+
err = buttonT.ExecuteTemplate(w, "base.html", btnd)
326
+
if err != nil {
327
+
http.Error(w, "error templating", http.StatusInternalServerError)
328
+
}
329
+
}
330
+
331
+
func (h *Handler) getbuttonauth(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) {
332
+
if cs == nil {
333
+
panic("cs must be non nil when i call getbuttonauth")
334
+
}
335
+
did := cs.Data.AccountDID.String()
336
+
uri := r.URL.Query().Get("uri")
337
+
btn, err := h.db.GetButtonAuth(uri, r.Context(), did)
338
+
if err != nil || btn == nil {
339
+
if err != nil {
340
+
log.Println(err)
341
+
}
342
+
http.Error(w, "not found", http.StatusNotFound)
343
+
return
344
+
}
345
+
type ButtonData struct {
346
+
DID *string
347
+
Title string
348
+
Button types.ButtonViewAuth
349
+
}
350
+
var btnd ButtonData
351
+
btnd.DID = &did
352
+
if btn.Alt != nil {
353
+
btnd.Title = *btn.Alt
354
+
} else {
355
+
btnd.Title = uri
356
+
}
357
+
btnd.Button = *btn
358
+
err = buttonT.ExecuteTemplate(w, "base.html", btnd)
359
if err != nil {
360
log.Println(err)
361
http.Error(w, "error templating", http.StatusInternalServerError)
+1
-1
tmpl/embedbase.html
···
6
<title>88x31s</title>
7
<style>
8
body {
9
-
margin: 0;
10
}
11
img {
12
image-rendering: {{.ImageRendering}};
···
6
<title>88x31s</title>
7
<style>
8
body {
9
+
margin: {{.Margin}}px;
10
}
11
img {
12
image-rendering: {{.ImageRendering}};