mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
fix slowness of previous refactors that injected nostr-sdk into this codebase + refactors.
- adjusting many small things related to nostr-sdk usage - fetching profiles in a smarter way - decoupling the logic for rendering profile pages from the `grabData`/`getEvent` flow of other event pages. - incorporating nostr-sdk more holistically, including more hints stuff - improving nostr-sdk itself after some bugs and weird behaviors observed here - set up opentelemetry (should probably remove this later)
This commit is contained in:
@@ -18,6 +18,8 @@ import (
|
||||
"github.com/golang/freetype/truetype"
|
||||
sdk "github.com/nbd-wtf/nostr-sdk"
|
||||
"github.com/nfnt/resize"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
xfont "golang.org/x/image/font"
|
||||
)
|
||||
|
||||
@@ -37,19 +39,24 @@ var fonts embed.FS
|
||||
var multiNewlineRe = regexp.MustCompile(`\n\n+`)
|
||||
|
||||
func renderImage(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
code := r.URL.Path[1+len("njump/image/"):]
|
||||
if code == "" {
|
||||
fmt.Fprintf(w, "call /njump/image/<nip19 code>")
|
||||
return
|
||||
}
|
||||
|
||||
ctx, span := tracer.Start(ctx, "render-image", trace.WithAttributes(attribute.String("code", code)))
|
||||
defer span.End()
|
||||
|
||||
// Trim fake extensions
|
||||
extensions := []string{".png", ".jpg", ".jpeg"}
|
||||
for _, ext := range extensions {
|
||||
code = strings.TrimSuffix(code, ext)
|
||||
}
|
||||
|
||||
data, err := grabData(r.Context(), code, false)
|
||||
data, err := grabData(ctx, code)
|
||||
if err != nil {
|
||||
http.Error(w, "error fetching event: "+err.Error(), 404)
|
||||
return
|
||||
@@ -63,8 +70,8 @@ func renderImage(w http.ResponseWriter, r *http.Request) {
|
||||
content = shortenURLs(content, true)
|
||||
|
||||
// this turns the raw event.Content into a series of lines ready to drawn
|
||||
paragraphs := replaceUserReferencesWithNames(r.Context(),
|
||||
quotesAsBlockPrefixedText(r.Context(),
|
||||
paragraphs := replaceUserReferencesWithNames(ctx,
|
||||
quotesAsBlockPrefixedText(ctx,
|
||||
strings.Split(content, "\n"),
|
||||
),
|
||||
string(INVISIBLE_SPACE),
|
||||
|
||||
Reference in New Issue
Block a user