mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 14:24:27 +01:00
log 404s and other log improvements.
This commit is contained in:
1
data.go
1
data.go
@@ -42,7 +42,6 @@ func grabData(ctx context.Context, code string) (Data, error) {
|
|||||||
// code can be a nevent or naddr, in which case we try to fetch the associated event
|
// code can be a nevent or naddr, in which case we try to fetch the associated event
|
||||||
event, relays, err := getEvent(ctx, code)
|
event, relays, err := getEvent(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Str("code", code).Msg("failed to fetch event for code")
|
|
||||||
return Data{}, fmt.Errorf("error fetching event: %w", err)
|
return Data{}, fmt.Errorf("error fetching event: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ func queueMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
count := concurrentRequests[qidx].Add(1)
|
count := concurrentRequests[qidx].Add(1)
|
||||||
isFirst := count == 1
|
isFirst := count == 1
|
||||||
if count > 2 {
|
if count > 2 {
|
||||||
log.Debug().Uint32("count", count).Int("qidx", qidx).Msg("too many concurrent requests")
|
log.Debug().Str("path", r.URL.Path).Uint32("count", count).Int("qidx", qidx).Str("ip", actualIP(r)).
|
||||||
|
Msg("too many concurrent requests")
|
||||||
|
|
||||||
if count > 4 {
|
if count > 4 {
|
||||||
http.Error(w, "", http.StatusTooManyRequests)
|
http.Error(w, "", http.StatusTooManyRequests)
|
||||||
|
|||||||
@@ -685,7 +685,7 @@ func drawShapedBlockAt(
|
|||||||
data := face.GlyphData(g.GlyphID)
|
data := face.GlyphData(g.GlyphID)
|
||||||
switch format := data.(type) {
|
switch format := data.(type) {
|
||||||
case api.GlyphOutline:
|
case api.GlyphOutline:
|
||||||
drawOutline(g, format, f, currentScale, xPos, yPos)
|
drawOutline(format, f, currentScale, xPos, yPos)
|
||||||
case nil:
|
case nil:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
@@ -829,7 +829,7 @@ func containsMedia(paragraphs []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this draws a font glyph (i.e. a letter) according to instructions and scale and whatever
|
// this draws a font glyph (i.e. a letter) according to instructions and scale and whatever
|
||||||
func drawOutline(g shaping.Glyph, bitmap api.GlyphOutline, f *rasterx.Filler, scale float32, x, y float32) {
|
func drawOutline(bitmap api.GlyphOutline, f *rasterx.Filler, scale float32, x, y float32) {
|
||||||
for _, s := range bitmap.Segments {
|
for _, s := range bitmap.Segments {
|
||||||
switch s.Op {
|
switch s.Op {
|
||||||
case api.SegmentOpMoveTo:
|
case api.SegmentOpMoveTo:
|
||||||
|
|||||||
1
nostr.go
1
nostr.go
@@ -177,7 +177,6 @@ func getEvent(ctx context.Context, code string) (*nostr.Event, []string, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if result == nil {
|
if result == nil {
|
||||||
log.Debug().Str("code", code).Msg("couldn't find")
|
|
||||||
return nil, nil, fmt.Errorf("couldn't find this %s, did you include relay or author hints in it?", prefix)
|
return nil, nil, fmt.Errorf("couldn't find this %s, did you include relay or author hints in it?", prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ func renderOEmbed(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
data, err := grabData(ctx, code)
|
data, err := grabData(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Header().Set("Cache-Control", "max-age=60")
|
w.Header().Set("Cache-Control", "max-age=180")
|
||||||
http.Error(w, "error fetching event: "+err.Error(), 404)
|
log.Warn().Err(err).Str("code", code).Msg("event not found on oembed")
|
||||||
|
http.Error(w, "error fetching event: "+err.Error(), http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// otherwise error
|
// otherwise error
|
||||||
w.Header().Set("Cache-Control", "max-age=60")
|
w.Header().Set("Cache-Control", "max-age=60")
|
||||||
|
log.Warn().Err(err).Str("code", code).Msg("invalid code")
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
errorTemplate(ErrorPageParams{Errors: err.Error()}).Render(ctx, w)
|
errorTemplate(ErrorPageParams{Errors: err.Error()}).Render(ctx, w)
|
||||||
return
|
return
|
||||||
@@ -65,6 +66,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
|||||||
data, err := grabData(ctx, code)
|
data, err := grabData(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Header().Set("Cache-Control", "max-age=60")
|
w.Header().Set("Cache-Control", "max-age=60")
|
||||||
|
log.Warn().Err(err).Str("code", code).Msg("event not found on render_event")
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
errorTemplate(ErrorPageParams{Errors: err.Error()}).Render(ctx, w)
|
errorTemplate(ErrorPageParams{Errors: err.Error()}).Render(ctx, w)
|
||||||
return
|
return
|
||||||
@@ -84,7 +86,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
|||||||
hasURL := urlRegex.MatchString(data.event.Content)
|
hasURL := urlRegex.MatchString(data.event.Content)
|
||||||
if hasURL && hasProhibitedWordOrTag(data.event.Event) {
|
if hasURL && hasProhibitedWordOrTag(data.event.Event) {
|
||||||
log.Warn().Str("event", data.nevent).Msg("detect prohibited porn content")
|
log.Warn().Str("event", data.nevent).Msg("detect prohibited porn content")
|
||||||
http.Error(w, "event is not allowed", 404)
|
http.Error(w, "event is not allowed", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ func renderImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
data, err := grabData(ctx, code)
|
data, err := grabData(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "error fetching event: "+err.Error(), 404)
|
http.Error(w, "error fetching event: "+err.Error(), http.StatusNotFound)
|
||||||
|
log.Warn().Err(err).Str("code", code).Msg("event not found on render_image")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ func renderProfile(ctx context.Context, r *http.Request, w http.ResponseWriter,
|
|||||||
|
|
||||||
profile, err := sys.FetchProfileFromInput(ctx, code)
|
profile, err := sys.FetchProfileFromInput(ctx, code)
|
||||||
if err != nil || profile.Event == nil {
|
if err != nil || profile.Event == nil {
|
||||||
|
log.Warn().Err(err).Str("code", code).Msg("event not found on render_profile")
|
||||||
w.Header().Set("Cache-Control", "max-age=60")
|
w.Header().Set("Cache-Control", "max-age=60")
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func renderSitemapIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
if len(npubs) != 0 {
|
if len(npubs) != 0 {
|
||||||
w.Header().Set("Cache-Control", "max-age=3600")
|
w.Header().Set("Cache-Control", "max-age=3600")
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Cache-Control", "max-age=60")
|
w.Header().Set("Cache-Control", "max-age=180")
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("content-type", "text/xml")
|
w.Header().Add("content-type", "text/xml")
|
||||||
|
|||||||
Reference in New Issue
Block a user