Skip to content

Commit b8af7fa

Browse files
committed
proxify image on separate path
1 parent c7f66ff commit b8af7fa

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/api/Action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { proxify } from '../utils/proxify.ts';
1+
import { proxify, proxifyImage } from '../utils/proxify.ts';
22
import type { ActionAdapter } from './ActionConfig.ts';
33
import type {
44
ActionError,
@@ -37,7 +37,7 @@ export class Action {
3737
}
3838

3939
public get icon() {
40-
return proxify(this._data.icon).toString();
40+
return proxifyImage(this._data.icon).toString();
4141
}
4242

4343
public get title() {

src/utils/proxify.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,30 @@ export function setProxyUrl(url: string): void {
2121

2222
export function proxify(url: string): URL {
2323
const baseUrl = new URL(url);
24-
if (baseUrl.hostname === 'localhost' || baseUrl.hostname === '127.0.0.1') {
24+
if (shouldIgnoreProxy(baseUrl)) {
2525
return baseUrl;
2626
}
27-
if (!proxyUrl) {
27+
const proxifiedUrl = new URL(proxyUrl!);
28+
proxifiedUrl.searchParams.set('url', url);
29+
return proxifiedUrl;
30+
}
31+
32+
export function proxifyImage(url: string): URL {
33+
const baseUrl = new URL(url);
34+
if (shouldIgnoreProxy(baseUrl)) {
2835
return baseUrl;
2936
}
30-
const proxifiedUrl = new URL(proxyUrl);
37+
const proxifiedUrl = new URL(`${proxyUrl!}/image`);
3138
proxifiedUrl.searchParams.set('url', url);
3239
return proxifiedUrl;
3340
}
41+
42+
function shouldIgnoreProxy(url: URL): boolean {
43+
if (url.hostname === 'localhost' || url.hostname === '127.0.0.1') {
44+
return true;
45+
}
46+
if (!proxyUrl) {
47+
return true;
48+
}
49+
return false;
50+
}

0 commit comments

Comments
 (0)