fix: image proxy url (#14505)

#### PR Dependency Tree


* **PR #14505** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Improvements**
* Better image-proxy detection to avoid double-proxying already proxied
images.
* Improved runtime image proxy configuration so images load consistently
across deployments.
* More robust image URL handling for optimized image loading and fewer
redundant requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2026-02-24 03:29:17 +08:00
committed by GitHub
parent 3e39dbb298
commit 5fb1c11a96
3 changed files with 26 additions and 10 deletions

View File

@@ -21,12 +21,24 @@ const imageProxyMiddlewareBuilder = () => {
};
};
const IMAGE_PROXY_PATH = '/api/worker/image-proxy';
export const isImageProxyURL = (imageUrl: string) => {
try {
const url = new URL(imageUrl, globalThis.location.origin);
return url.pathname === IMAGE_PROXY_PATH && url.searchParams.has('url');
} catch {
return false;
}
};
const defaultImageProxyMiddlewarBuilder = imageProxyMiddlewareBuilder();
export const setImageProxyMiddlewareURL = defaultImageProxyMiddlewarBuilder.set;
export const defaultImageProxyMiddleware =
defaultImageProxyMiddlewarBuilder.get();
export const defaultImageProxyMiddleware: TransformerMiddleware = args => {
return defaultImageProxyMiddlewarBuilder.get()(args);
};
// TODO(@mirone): this should be configured when setup instead of runtime
export class ImageProxyService extends StoreExtension {
@@ -40,7 +52,7 @@ export class ImageProxyService extends StoreExtension {
}
buildUrl(imageUrl: string) {
if (imageUrl.startsWith(this.imageProxyURL)) {
if (imageUrl.startsWith(this.imageProxyURL) || isImageProxyURL(imageUrl)) {
return imageUrl;
}