From 4eb52d11c002c4b89b40e35fa3a8b947e1d14f9a Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 5 Nov 2025 08:06:48 +0100 Subject: [PATCH] Handles relative redirects for remote images Ensures that relative redirect URLs are resolved against the original image URL. This prevents issues when downloading remote images from servers that return relative redirect paths. --- src/plugin/EmbedProcessor.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugin/EmbedProcessor.ts b/src/plugin/EmbedProcessor.ts index df66cce..aba8d18 100644 --- a/src/plugin/EmbedProcessor.ts +++ b/src/plugin/EmbedProcessor.ts @@ -115,9 +115,13 @@ export class EmbedProcessor { if (response.statusCode === 301 || response.statusCode === 302) { const redirectUrl = response.headers.location; if (redirectUrl) { - console.log(`Export: Following redirect to: ${redirectUrl}`); - // Recursively follow redirect - this.downloadRemoteImage(redirectUrl, tempDir).then(resolve); + // Resolve relative redirects against the original request URL + // This handles both absolute URLs (e.g., "https://example.com/img.png") + // and relative URLs (e.g., "/assets/img.png" or "../img.png") + const absoluteRedirectUrl = new URL(redirectUrl, imageUrl).href; + console.log(`Export: Following redirect to: ${absoluteRedirectUrl}`); + // Recursively follow redirect with resolved absolute URL + this.downloadRemoteImage(absoluteRedirectUrl, tempDir).then(resolve); return; } }