子哥工作室

文章 分类 评论
27 1 6

站点介绍

这里是子哥的博客,会不定时的发一些VPS冷知识、建站技巧以及各种白嫖小妙招哦~

Cloudflare反代加速Onedrive

子哥科技 2022-07-19 216 2条评论 默认分类 Cloudflare反代加速Onedrive反代加速OnedriveOnedrive直链

首页 / 正文
请浏览本站的朋友们遵守当地的法律法规!

发布于2022-07-19

序言

我们在使用Onedrive时下载速度总是差强人意,这是我们只需要获取Onedrive的直链就可以了。

开始操作

登录后台

clouflare后台

创建workers服务

如图所示,点击创建服务,右侧显示每天的额度,如果只是搭建个人服务这些额度绰绰有余了。下方会显示所有已经搭建的服务。
创建服务

进入创建服务页面后,我们要稍微配置一下这个服务名称,将他改为自己心仪的名称,因为以后我们要用他访问镜像站(2022年后workers.dev就被墙了)
创建函数

这样我们的服务就搭建好了。但是我们还需要修改代码。转到控制界面,可以找到右下角有一个快速编辑的按钮。
控制界面

左边修改代码,下方部署,右侧可以选择预览窗口,以及打开链接。

一般我们就打开这个页面,把下方的代码复制进去,点击保存部署,然后输入链接就可以直接访问Tiktok镜像站了。
部署代码

代码内容

// 替换成你OneDrive的网址
const upstream = '-my.sharepoint.com'
const upstream_mobile = '-my.sharepoint.com'
 
// 下面的配置都不用动
const upstream_path = '/'
 
const blocked_region = ['KP', 'SY', 'PK', 'CU']
 
const blocked_ip_address = ['0.0.0.0', '127.0.0.1']
 
const https = true
 
const disable_cache = false
 
const replace_dict = {
    '$upstream': '$custom_domain',
    '//sunpma.com': ''
}
 
addEventListener('fetch', event => {
    event.respondWith(fetchAndApply(event.request));
})
 
async function fetchAndApply(request) {
    const region = request.headers.get('cf-ipcountry').toUpperCase();
    const ip_address = request.headers.get('cf-connecting-ip');
    const user_agent = request.headers.get('user-agent');
 
    let response = null;
    let url = new URL(request.url);
    let url_hostname = url.hostname;
 
    if (https == true) {
        url.protocol = 'https:';
    } else {
        url.protocol = 'http:';
    }
 
    if (await device_status(user_agent)) {
        var upstream_domain = upstream;
    } else {
        var upstream_domain = upstream_mobile;
    }
 
    url.host = upstream_domain;
    if (url.pathname == '/') {
        url.pathname = upstream_path;
    } else {
        url.pathname = upstream_path + url.pathname;
    }
 
    if (blocked_region.includes(region)) {
        response = new Response('Access denied: WorkersProxy is not available in your region yet.', {
            status: 403
        });
    } else if (blocked_ip_address.includes(ip_address)) {
        response = new Response('Access denied: Your IP address is blocked by WorkersProxy.', {
            status: 403
        });
    } else {
        let method = request.method;
        let request_headers = request.headers;
        let new_request_headers = new Headers(request_headers);
 
        new_request_headers.set('Host', upstream_domain);
        new_request_headers.set('Referer', url.protocol + '//' + url_hostname);
 
        let original_response = await fetch(url.href, {
            method: method,
            headers: new_request_headers
        })
 
        connection_upgrade = new_request_headers.get("Upgrade");
        if (connection_upgrade && connection_upgrade.toLowerCase() == "websocket") {
            return original_response;
        }
 
        let original_response_clone = original_response.clone();
        let original_text = null;
        let response_headers = original_response.headers;
        let new_response_headers = new Headers(response_headers);
        let status = original_response.status;
  
        if (disable_cache) {
            new_response_headers.set('Cache-Control', 'no-store');
        }
 
        new_response_headers.set('access-control-allow-origin', '*');
        new_response_headers.set('access-control-allow-credentials', true);
        new_response_headers.delete('content-security-policy');
        new_response_headers.delete('content-security-policy-report-only');
        new_response_headers.delete('clear-site-data');
  
        if (new_response_headers.get("x-pjax-url")) {
            new_response_headers.set("x-pjax-url", response_headers.get("x-pjax-url").replace("//" + upstream_domain, "//" + url_hostname));
        }
  
        const content_type = new_response_headers.get('content-type');
        if (content_type != null && content_type.includes('text/html') && content_type.includes('UTF-8')) {
            original_text = await replace_response_text(original_response_clone, upstream_domain, url_hostname);
        } else {
            original_text = original_response_clone.body
        }
  
        response = new Response(original_text, {
            status,
            headers: new_response_headers
        })
    }
    return response;
}
 
async function replace_response_text(response, upstream_domain, host_name) {
    let text = await response.text()
 
    var i, j;
    for (i in replace_dict) {
        j = replace_dict[i]
        if (i == '$upstream') {
            i = upstream_domain
        } else if (i == '$custom_domain') {
            i = host_name
        }
 
        if (j == '$upstream') {
            j = upstream_domain
        } else if (j == '$custom_domain') {
            j = host_name
        }
 
        let re = new RegExp(i, 'g')
        text = text.replace(re, j);
    }
    return text;
}
 
 
async function device_status(user_agent_info) {
    var agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < agents.length; v++) {
        if (user_agent_info.indexOf(agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

自定义域名

托管域名到Cloudflare

就是把自己的域名转移到CloudFlare这个很简单,到Cloudflare 主页点击添加站点即可托管。

新增DNS解析

进入自己的域名后转到DNS界面,添加一条‘AAAA“DNS解析,IPv6为100::,最重要的是打开小黄云(即打开Cloudflare代理)
DNS解析

关联域名

进入你的域名,不是你的首页!进入Workers,添加路由

评论(2)

  1. 老狼 游客 2022-07-19 16:14 回复

    请问无法使用怎么办呢?

    1. 子哥科技 管理员 2022-07-19 16:15 回复

      额,workers.dev被墙了

最新评论

  • Anna

    Hi I am Anna, We collaborate with startups, SMBs, and new domain owners to provide Website design - re-design and development services at modest rate. We have a dedicated team of 45 professional designers and developers with over 8 plus years of experience and we thrive on the idea that design makes a difference. Our services at a glance: - Website Designing/Re-Designing #E-commerce development (Magento, Shopify, Woo Commerce etc.) #Graphic Designing #WordPress Theme Design & Customization #Custom themes, Plugins & Widget Development #Custom Templates, Modules, Plugins Design & Development Please share your REQUIREMENT with your phone number (With Country Code) /Skype and suitable time (Meeting) to talk to you, So we can discuss and understand in detail. I’m waiting for your reply. Kinds Regards, Anna (Web Solution Manager)

  • 子哥科技

    不错啊,以后就可以存直播回放卖课啦[[呲牙]]

  • 苏陌染

    个人感觉,三丰云服务器就是属于那种中低端的吧

  • 不发财我就火烧豹王

    j=看起来还不错[[呲牙]]

  • 子哥科技

    额,workers.dev被墙了

  • 老狼

    请问无法使用怎么办呢?

日历

2022年10月

      1
2345678
9101112131415
16171819202122
23242526272829
3031     

友情链接

文章目录

站点公告
请浏览本站的朋友们遵守当地的法律法规!
点击小铃铛关闭