mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 14:24:27 +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:
@@ -6,6 +6,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func renderEmbedjs(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -15,11 +17,16 @@ func renderEmbedjs(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func renderEmbedded(w http.ResponseWriter, r *http.Request, code string) {
|
||||
data, err := grabData(r.Context(), code, false)
|
||||
ctx := r.Context()
|
||||
|
||||
ctx, span := tracer.Start(ctx, "render-embedded", trace.WithAttributes(attribute.String("code", code)))
|
||||
defer span.End()
|
||||
|
||||
data, err := grabData(ctx, code)
|
||||
if err != nil {
|
||||
w.Header().Set("Cache-Control", "max-age=60")
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
errorTemplate(ErrorPageParams{Errors: err.Error()}).Render(r.Context(), w)
|
||||
errorTemplate(ErrorPageParams{Errors: err.Error()}).Render(ctx, w)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -36,7 +43,7 @@ func renderEmbedded(w http.ResponseWriter, r *http.Request, code string) {
|
||||
// first we run basicFormatting, which turns URLs into their appropriate HTML tags
|
||||
data.content = basicFormatting(html.EscapeString(data.content), true, false, false)
|
||||
// then we render quotes as HTML, which will also apply basicFormatting to all the internal quotes
|
||||
data.content = renderQuotesAsHTML(r.Context(), data.content, data.templateId == TelegramInstantView)
|
||||
data.content = renderQuotesAsHTML(ctx, data.content, data.templateId == TelegramInstantView)
|
||||
// we must do this because inside <blockquotes> we must treat <img>s differently when telegram_instant_view
|
||||
}
|
||||
|
||||
@@ -56,7 +63,7 @@ func renderEmbedded(w http.ResponseWriter, r *http.Request, code string) {
|
||||
Metadata: data.event.author,
|
||||
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.event.author.Website),
|
||||
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.event.author.About), false, false, true)),
|
||||
AuthorRelays: data.authorRelaysPretty(r.Context()),
|
||||
AuthorRelays: relaysPretty(ctx, data.event.author.PubKey),
|
||||
})
|
||||
default:
|
||||
log.Error().Int("templateId", int(data.templateId)).Msg("no way to render")
|
||||
@@ -64,7 +71,7 @@ func renderEmbedded(w http.ResponseWriter, r *http.Request, code string) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := component.Render(r.Context(), w); err != nil {
|
||||
if err := component.Render(ctx, w); err != nil {
|
||||
log.Warn().Err(err).Msg("error rendering tmpl")
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user