网友 未完的歌 说:
*帖最后由 未完的歌 于 2022-5-27 11:02 编辑
因为有验证hash,我自己用,就先把这个注释掉
- // 允许的 CORS 来源
- const ALLOWED_REFERER = [
- /^https?:\/\/自己worker域名(:\d*)?\/.*$/,
- /^https?:\/\/([\w-]+\.)*w3schools\.com(:\d*)?\/.*$/
- ];
- // 是否允许所有无 Referer 请求
- const ALLOW_NO_ORIGIN = true;
- //输入你的密码,密码加在path后面做SHA-1运算
- const **SECRET = &*uot;123456&*uot;;
- function validateReferer(re*) {
- const referer = re*.headers.get(‘Referer’);
- if (referer) {
- for (const el of ALLOWED_REFERER) {
- if (el.exec(referer)) {
- ret**n true;
- }
- }
- ret**n false;
- }
- ret**n ALLOW_NO_ORIGIN; // 是否拒绝所有无 Referer 请求
- }
- async function handle(re*uest) {
- let **l = new **L(re*uest.**l);
- const acceptType = re*uest.headers.get(‘Accept’);
- const hash_re*uest = **l.pathname.split(&*uot;/&*uot;)[1];
- const path_real = **l.pathname.subst**ng(1, **l.pathname.len***);
- **l.hostname = &*uot;cdn.jsdelivr.net&*uot;;
- **l.pathname = path_real;
- // if (!(await validatePath(hash_re*uest, path_real))) {
- // ret**n new Response(‘Er**r Hash’, {
- // status: 403
- // });
- // }
- // if (!(validateReferer(re*uest))) {
- // ret**n new Response(‘Blocked Host’, {
- // status: 403
- // });
- // }
- ret**n await fetch(**l);
- }
- async function validatePath(hash_re*uest, path_real) {
- const me**age = new TextEncoder().encode(path_real + **SECRET);
- const myDigest = await crypto.su**le.digest(‘SHA-1’, me**age);
- const hashArray = Array.f**m(new Uint8Array(myDigest));
- const hashHex = hashArray.map(b => b.toSt**ng(16).padStart(2, ‘0’)).join(”);
- ret**n (hashHex == hash_re*uest);
- }
- addEventListener(‘fetch’,
- ***nt => {
- ***nt.respondWith(handle(***nt.re*uest));
- })
网友 lowan 说:
..
网友 haozi 说:
worker那速度,整个**小鸡不香吗
网友 s*zryang 说:
你猜我为啥用jsdeliver
未经允许不得转载:爱主机 » workers 反代 jsdeliver
爱主机