Skip to content

Commit 08c2006

Browse files
authored
fix: portrait exports should be real portraits (#854)
1 parent dfc7909 commit 08c2006

13 files changed

+54
-8
lines changed

pkg/api/middleware/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ var MetricAuthenticatedRequestAttempt = prometheus.NewCounterVec(prometheus.Coun
1616
func RequireAuthToken(h http.Handler, expectedTokens ...string) http.Handler {
1717
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1818
tracer := tracer(r.Context())
19-
ctx, span := tracer.Start(r.Context(), "RequireAuthToken")
19+
_, span := tracer.Start(r.Context(), "RequireAuthToken")
2020
defer span.End()
21-
r = r.WithContext(ctx)
2221

2322
token := r.Header.Get("X-Auth-Token")
2423
if token == "" {
@@ -28,6 +27,7 @@ func RequireAuthToken(h http.Handler, expectedTokens ...string) http.Handler {
2827
}
2928
if slices.Contains(expectedTokens, token) {
3029
MetricAuthenticatedRequestAttempt.WithLabelValues("valid-token").Inc()
30+
span.End() // we don't want to track the next middleware in this span
3131
h.ServeHTTP(w, r)
3232
return
3333
}

pkg/api/middleware/ratelimiter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func (p processBasedLimiter) Limit(next http.Handler) http.Handler {
7272
// > Consider using the more ergonomic and less error-prone [Uint32.Add] instead.
7373
defer p.running.Add(^uint32(0)) // decrement
7474

75+
span.End() // we don't want to track the next middleware in this span
7576
next.ServeHTTP(w, r)
7677
}
7778
})

pkg/api/middleware/recovery.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func Recovery(h http.Handler) http.Handler {
3030
span.SetStatus(codes.Error, "panic in HTTP handler")
3131
}
3232
}()
33+
3334
h.ServeHTTP(w, r)
3435
span.SetStatus(codes.Ok, "no panic")
3536
})

pkg/api/middleware/trustedurl.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ var MetricTrustedURLRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
1616
func TrustedURL(h http.Handler) http.Handler {
1717
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1818
tracer := tracer(r.Context())
19-
ctx, span := tracer.Start(r.Context(), "TrustedURL")
19+
_, span := tracer.Start(r.Context(), "TrustedURL")
2020
defer span.End()
21-
r = r.WithContext(ctx)
2221

2322
urlQuery := r.URL.Query().Get("url")
2423
if urlQuery == "" {
2524
// Nothing to check: let it through.
2625
MetricTrustedURLRequests.WithLabelValues("missing-query").Inc()
26+
span.End() // we don't want to track the next middleware in this span
2727
h.ServeHTTP(w, r)
2828
return
2929
}
@@ -42,6 +42,7 @@ func TrustedURL(h http.Handler) http.Handler {
4242
}
4343

4444
MetricTrustedURLRequests.WithLabelValues("valid").Inc()
45+
span.End() // we don't want to track the next middleware in this span
4546
h.ServeHTTP(w, r)
4647
})
4748
}

pkg/api/render.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,14 @@ func HandleGetRender(browser *service.BrowserService) http.Handler {
193193
}
194194
span.SetAttributes(attribute.String("encoding", "pdf"))
195195

196-
if pdfLandscape := r.URL.Query().Get("pdfLandscape"); pdfLandscape != "" {
196+
pdfLandscape := r.URL.Query().Get("pdf.landscape")
197+
if pdfLandscape == "" {
198+
// FIXME: legacy support; remove in some future release.
199+
pdfLandscape = targetURL.Query().Get("pdf.landscape")
200+
}
201+
if pdfLandscape != "" {
197202
options = append(options, service.WithLandscape(pdfLandscape == "true"))
198-
span.SetAttributes(attribute.Bool("pdfLandscape", pdfLandscape == "true"))
203+
span.SetAttributes(attribute.Bool("pdf.landscape", pdfLandscape == "true"))
199204
}
200205
case "png":
201206
var printerOpts []service.PNGPrinterOption

pkg/service/browser.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,14 @@ func (p *pngPrinter) prepare(cfg config.BrowserConfig) chromedp.Action {
782782
orientation = chromedp.EmulateLandscape
783783
}
784784

785-
err = chromedp.EmulateViewport(int64(cfg.MinWidth), int64(scrollHeight), orientation).Do(ctx)
785+
var width, height int64
786+
if cfg.Landscape {
787+
width, height = int64(cfg.MinHeight), int64(scrollHeight)
788+
} else {
789+
width, height = int64(cfg.MinWidth), int64(scrollHeight)
790+
}
791+
792+
err = chromedp.EmulateViewport(width, height, orientation).Do(ctx)
786793
if err != nil {
787794
span.SetStatus(codes.Error, "failed to resize viewport: "+err.Error())
788795
return fmt.Errorf("failed to resize viewport for full height: %w", err)
-29.5 KB
Loading
-27.5 KB
Loading
422 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)