File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 11import { GM_fetch , gmOk } from './gm' ;
2- import { isAllowCorsUrl } from './url' ;
2+ import { isCanProxyImportFileUrl , isAllowCorsUrl } from './url' ;
33
44export 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` ) ;
Original file line number Diff line number Diff line change @@ -39,6 +39,16 @@ const urlRegList = [
3939 / ^ h t t p s : \/ \/ i \. g k d \. l i \/ i m p o r t \/ ( \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+
4252export const getImportId = ( url : string ) => {
4353 if ( typeof url !== 'string' ) return ;
4454 if ( url . startsWith ( location . origin ) ) {
You can’t perform that action at this time.
0 commit comments