Repository navigation
Redirect Jellyfin image routes to upstream URLs - #101
Conversation
📝 WalkthroughWalkthroughHandlers now call serveImageURL which either proxies upstream bytes or issues an HTTP 302 redirect based on request classification. Adds redirectImageURL/parseRemoteImageURL, a compat image proxy route/ID scheme, middleware to rewrite image tags in JSON responses, tag canonicalization, codec/DTO updates, and tests adjusted for redirect behavior. ChangesImage compat delivery to proxy-or-redirect with tag middleware
Sequence Diagram(s)sequenceDiagram
Client->>compatImageProxyTagVariantMiddleware: GET /api/... (JSON responses)
compatImageProxyTagVariantMiddleware->>ImagesHandler: forwarded request (possibly wrapped)
ImagesHandler->>ImageCache: lookup (tag/route canonicalization)
ImagesHandler->>ImagesHandler: shouldProxyCompatImageRequest?
alt proxy
ImagesHandler->>HTTPClient: fetch upstream image (proxyImage)
HTTPClient->>UpstreamOrigin: GET image URL
UpstreamOrigin-->>HTTPClient: response (status, headers, body)
HTTPClient-->>ImagesHandler: proxied response streamed
ImagesHandler-->>Client: proxied bytes (no-store headers)
else redirect
ImagesHandler-->>Client: 302 Redirect (Location: upstream URL, no-store)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3bf0367eec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Do not let clients cache the temporary redirect itself. The object-store | ||
| // response can still carry its own cache headers after the client follows it. | ||
| w.Header().Set("Cache-Control", "no-store") | ||
| http.Redirect(w, r, imageURL, http.StatusFound) |
There was a problem hiding this comment.
Keep server-only presigned endpoints behind the proxy
When the public asset bucket uses the default presigned URL auth and s3.public_endpoint points at an object-store endpoint that is only reachable from the Silo server/container, this now sends Jellyfin clients directly to that internal host. The S3 client signs presigned URLs against its configured endpoint unless URL auth is public/cloudflare_token, so deployments that previously worked because the compat handler fetched the image server-side will start returning unusable redirects for cached/plugin/library artwork.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (3)
internal/jellycompat/handlers_images.go (1)
456-459: 💤 Low valueRedundant nil check for httpClient.
The
NewImagesHandlerconstructor already defaultshttpClienttohttp.DefaultClientwhen nil (lines 54-56). This defensive check is unnecessary unlessproxyImageURLmight be called on a zero-valuedImagesHandler.♻️ Suggested simplification
- client := h.httpClient - if client == nil { - client = http.DefaultClient - } - resp, err := client.Do(req) + resp, err := h.httpClient.Do(req)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/jellycompat/handlers_images.go` around lines 456 - 459, The nil-check for httpClient in proxyImageURL is redundant because NewImagesHandler already sets h.httpClient to http.DefaultClient when nil; remove the defensive check in proxyImageURL (the block referencing client := h.httpClient and the if client == nil branch) and use h.httpClient directly, or alternatively ensure proxyImageURL is only ever called on a properly constructed ImagesHandler; keep references to ImagesHandler, NewImagesHandler, and proxyImageURL to locate the change.internal/jellycompat/image_proxy_tags.go (1)
41-54: 💤 Low valueConsider memory implications of buffering entire JSON responses.
The middleware buffers the complete response body in memory (line 53) before rewriting. For large paginated result sets or detailed item metadata, this could consume significant memory under load. While this approach is necessary for JSON rewriting without a streaming parser, consider documenting the memory trade-off or enforcing reasonable pagination limits upstream.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/jellycompat/image_proxy_tags.go` around lines 41 - 54, compatImageProxyTagResponseWriter.Write buffers the entire JSON response into compatImageProxyTagResponseWriter.body which can blow memory for large responses; update the implementation to guard against that by checking buffered size and switching to passthrough (set passthrough true and forward writes to ResponseWriter) once a configurable maxBufferBytes is exceeded, and add a clear comment/doc on the memory trade-off and the new maxBufferBytes config; reference the Write method, the body buffer, passthrough flag, and isJSONResponse check so reviewers can locate and validate the change.internal/jellycompat/images_test.go (1)
67-144: ⚡ Quick winConsider adding test coverage for 304 Not Modified responses.
The test forwards the
If-None-Matchheader (line 110) and verifies it reaches upstream (lines 138-140), but the upstream always returns 200 OK. According to the AI summary,TestProxyImageRelaysNotModifiedwas removed.Consider adding test coverage to verify that when the upstream returns
304 Not Modified, the proxy correctly relays this status and headers to the client.Test case suggestion
Add a test where the upstream returns 304:
func TestHandleItemImageProxyRelays304NotModified(t *testing.T) { upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Header.Get("If-None-Match") == `"poster-v1"` { w.Header().Set("ETag", `"poster-v1"`) w.Header().Set("Cache-Control", "public, max-age=14400") w.WriteHeader(http.StatusNotModified) return } w.WriteHeader(http.StatusOK) })) defer upstream.Close() // ... setup handler with Infuse user-agent and httpClient ... // ... make request with If-None-Match header ... // Assert response is 304 with proper headers }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/jellycompat/images_test.go` around lines 67 - 144, Add a new test (e.g., TestHandleItemImageProxyRelays304NotModified) that mirrors TestHandleItemImageProxiesInfuseSignedTagWithoutSessionOrCache but uses an upstream httptest.Server that returns http.StatusNotModified (304) when the forwarded If-None-Match equals `"poster-v1"`; construct the same ImagesHandler (reuse NewResourceIDCodec, newImageTagSigner(cfg.Auth.JWTSecret), NewImageCache, fakeImageItemRepo, and set httpClient to upstream.Client()), send the request with the Infuse User-Agent and If-None-Match header, call ImagesHandler.HandleItemImage, and assert the response code is 304, the ETag and Cache-Control headers from upstream are relayed (and compatImageRouteCacheControl/CDN-Cache-Control/X-Accel-Expires are set appropriately), the body is empty, and no Location header is set.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/jellycompat/handlers_images.go`:
- Around line 456-459: The nil-check for httpClient in proxyImageURL is
redundant because NewImagesHandler already sets h.httpClient to
http.DefaultClient when nil; remove the defensive check in proxyImageURL (the
block referencing client := h.httpClient and the if client == nil branch) and
use h.httpClient directly, or alternatively ensure proxyImageURL is only ever
called on a properly constructed ImagesHandler; keep references to
ImagesHandler, NewImagesHandler, and proxyImageURL to locate the change.
In `@internal/jellycompat/image_proxy_tags.go`:
- Around line 41-54: compatImageProxyTagResponseWriter.Write buffers the entire
JSON response into compatImageProxyTagResponseWriter.body which can blow memory
for large responses; update the implementation to guard against that by checking
buffered size and switching to passthrough (set passthrough true and forward
writes to ResponseWriter) once a configurable maxBufferBytes is exceeded, and
add a clear comment/doc on the memory trade-off and the new maxBufferBytes
config; reference the Write method, the body buffer, passthrough flag, and
isJSONResponse check so reviewers can locate and validate the change.
In `@internal/jellycompat/images_test.go`:
- Around line 67-144: Add a new test (e.g.,
TestHandleItemImageProxyRelays304NotModified) that mirrors
TestHandleItemImageProxiesInfuseSignedTagWithoutSessionOrCache but uses an
upstream httptest.Server that returns http.StatusNotModified (304) when the
forwarded If-None-Match equals `"poster-v1"`; construct the same ImagesHandler
(reuse NewResourceIDCodec, newImageTagSigner(cfg.Auth.JWTSecret), NewImageCache,
fakeImageItemRepo, and set httpClient to upstream.Client()), send the request
with the Infuse User-Agent and If-None-Match header, call
ImagesHandler.HandleItemImage, and assert the response code is 304, the ETag and
Cache-Control headers from upstream are relayed (and
compatImageRouteCacheControl/CDN-Cache-Control/X-Accel-Expires are set
appropriately), the body is empty, and no Location header is set.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a4ef9dc2-d14e-4265-bd17-e4b000af6d1f
📒 Files selected for processing (11)
internal/jellycompat/dto.gointernal/jellycompat/handlers_images.gointernal/jellycompat/idcodec.gointernal/jellycompat/image_cache.gointernal/jellycompat/image_proxy_tags.gointernal/jellycompat/image_proxy_tags_test.gointernal/jellycompat/image_tag_signer.gointernal/jellycompat/images.gointernal/jellycompat/images_test.gointernal/jellycompat/router.gointernal/jellycompat/server.go
* Redirect Jellyfin image routes to upstream URLs * fix(jellycompat): proxy images for incompatible clients
* Redirect Jellyfin image routes to upstream URLs * fix(jellycompat): proxy images for incompatible clients
Generated from silo-translations main at 8b0ffaa (#101). Re-pin to the published release before merge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…3611) * feat(plugins): apply plugin task bindings and lifecycle changes live Co-Authored-By: Claude Fable 5.2 <[email protected]> * fix(taskmanager): keep firings that a schedule change or unregister raced - The trigger loop ignores an update signal whose generation it has already read, so a signal left from an edit during a run no longer discards the new trigger's firing. - A worker retired after its trigger fired returns before claiming the firing, so other servers don't skip a firing that runs nowhere. - A startup trigger stopped before it fires arms again on the next Start, so the rearm after a run keeps a startup schedule installed during that run. - Unregistering a task publishes task.updated, so task lists drop it. - API and architecture text now says how plugin task edits reach other servers and that disabling a binding cancels a run in progress. Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore(web): sync translations for the plugin task panel text Generated from silo-translations main at 8b0ffaa (#101). Re-pin to the published release before merge. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tasks): coordinate live schedules with firing and retirement * chore(api): retire the consumed playback history approval --------- Co-authored-by: Claude Fable 5.2 <[email protected]>
Summary
Testing
Summary by CodeRabbit
New Features
Bug Fixes
Tests