Skip to content

Commit 9e4dd48

Browse files
committed
feat: add proxyUrl
1 parent 1581743 commit 9e4dd48

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/utils/fetch.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
import { GM_fetch, gmOk } from './gm';
2-
import { isAllowCorsUrl } from './url';
2+
import { isCanProxyImportFileUrl, isAllowCorsUrl } from './url';
33

44
export const enhanceFetch = async (
55
input: RequestInfo | URL,
66
init?: RequestInit,
7-
) => {
7+
): Promise<Response> => {
88
const req = new Request(input);
99
const u = new URL(req.url);
1010
if (isAllowCorsUrl(u)) return fetch(input, init);
1111
if (gmOk()) {
1212
// with cookie
1313
// export snapshot need
1414
return GM_fetch(input, init);
15+
} else if (isCanProxyImportFileUrl(u.href)) {
16+
const proxyUrl = new URL(`https://proxy.gkd.li`);
17+
proxyUrl.searchParams.set(`proxyUrl`, u.href);
18+
const request = new Request(input, init);
19+
return fetch(proxyUrl, {
20+
method: request.method,
21+
headers: request.headers,
22+
body: request.body,
23+
});
1524
} else {
1625
useGlobalStore().networkErrorDlgVisible = true;
1726
throw new Error(`gm is not supported`);

src/utils/url.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ const urlRegList = [
3939
/^https:\/\/i\.gkd\.li\/import\/(\d+)$/,
4040
];
4141

42+
const fileBaseUrlList = [
43+
'https://f.gkd.li/',
44+
'https://github.com/user-attachments/files/',
45+
'https://github.com/gkd-kit/inspect/files/',
46+
];
47+
48+
export const isCanProxyImportFileUrl = (url: string): boolean => {
49+
return fileBaseUrlList.some((v) => url.startsWith(v));
50+
};
51+
4252
export const getImportId = (url: string) => {
4353
if (typeof url !== 'string') return;
4454
if (url.startsWith(location.origin)) {

0 commit comments

Comments
 (0)