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