mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 06:44: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:
10
oembed.go
10
oembed.go
@@ -7,6 +7,9 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type OEmbedResponse struct {
|
||||
@@ -37,6 +40,8 @@ type OEmbedResponse struct {
|
||||
}
|
||||
|
||||
func renderOEmbed(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
targetURL, err := url.Parse(r.URL.Query().Get("url"))
|
||||
if err != nil {
|
||||
http.Error(w, "invalid url: "+err.Error(), 400)
|
||||
@@ -49,9 +54,12 @@ func renderOEmbed(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx, span := tracer.Start(ctx, "render-oembed", trace.WithAttributes(attribute.String("code", code)))
|
||||
defer span.End()
|
||||
|
||||
host := r.Header.Get("X-Forwarded-Host")
|
||||
|
||||
data, err := grabData(r.Context(), code, false)
|
||||
data, err := grabData(ctx, code)
|
||||
if err != nil {
|
||||
w.Header().Set("Cache-Control", "max-age=60")
|
||||
http.Error(w, "error fetching event: "+err.Error(), 404)
|
||||
|
||||
Reference in New Issue
Block a user