-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
35 lines (28 loc) · 818 Bytes
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export interface CacheUrl {
hostname: string;
pathname: string;
getRealUrl?: (url: string) => string,
}
export const defaultCacheUrls: CacheUrl[] = [
{
hostname: 'yandexwebcache.net',
pathname: '/yandbtm',
getRealUrl: (url) => {
const parsed = new URL(url);
return parsed.searchParams.get('url');
},
},
{
hostname: 'webcache.googleusercontent.com',
pathname: '/search',
getRealUrl: (url) => {
const parsed = new URL(url);
const q = parsed.searchParams.get('q');
const matched = q.match(/^cache:[^:]+:(.+)/);
if (!matched) throw new Error(`Can't extract realUrl from "${url}"`);
const extracted = matched[1].trim();
if (!extracted.startsWith('https://')) return `http://${extracted}`;
return extracted;
},
},
];