使用onedrive搭建网盘

一、概述

onemanager是一款强大的OneDrive目录列表程序,支持的功能比OneIndex更多。支持无服务器一键搭建,支持腾讯SCF服务搭建,基本上能用的搭建方式都支持,而且支持OneDrive商业版、OneDrive个人版和世纪互联版。支持多盘绑定,支持访客上传文件,图床模式,可以让访客上传文件做为图床使用,非常的方便。

二、注册账号

GitHub开源网址:https://github.com/qkqpttgf/OneManager-php

  1. 首先把项目fork到自己的github上。

  2. 进入到github中,可以看到这个醒目的button,这篇文章正是利用heroku搭建免费的onemanager,不需要其他的服务器和主机。 点击那个按钮,进入注册(需要富强,注册引入了google人机验证),qq邮箱已被屏蔽。
    file

三、创建app

在“App name”填写您的应用名称,“Choose a region”选择一个服务区域选择“United States”。 注意:“App name”填写的应用名称就是您次域名.herokuapp.com的前缀,名称必须以小写字母开头
file
点击“Deploy app”部署应用稍等片刻即可完成初始化。再点击“Manager APP”管理应用程序

file
点击“Setting”设置应用,直接往下拉在“Domains”处可以看到您的次域名(如果您已经填加了信用卡账户已验证,可以绑定自己的域名)点击您的次域名。
file

file

四、安装

单击此处“开始部署”安装OneManager-PHP项目
file
在“API Key”处点击后面的“Reveal”显示您的API Key。复制
file
复制API Key粘贴至API Key。“Set admin password”设置管理员密码,点击“确认”。
file

五、配置

安装完成后登陆➠管理➠设置,添加OneDrive盘。
打开网址:https:yourappname.heroku.com

file
点击添加onedrive盘

file

标签和显示名称随便填,点击‘申请应用ID与机密‘
file
点击'新注册',注册个应用
file
点击左侧身份认证,右侧添加平台
file

file

重定向地址:https://scfonedrive.github.io/

file

点击左侧证书与密码

file
截止日期,我选择24个月,说明可以空

file

记住下面的值,非机密id
file

复制应用程序ID
file
复制下面的值
file
填写前面复制的应用程序ID和值
file
保持默认即可。

file

六、测试

打开https://yourappname.heroku.com
我的网盘里新建了test目录,所以这里就显示了。

file

七、基本设置

登录管理员后,点管理--设置
file

点击平台变量,下面参数根据自己需要更改。
file

八、通过cf反代

登录cloudflare,点击 某个域名
file

,点击下面的worker
file
点击创建worker,将反代代码复制到workers里面(点击此处复制),并将图中两个域名都换成你的onemenager的域名(至于为什么是两个,这是因为heroku一个月只有550小时,不够某些人使用,所以单双日填不同的域名可以单日和双日访问不同的heroku。如果你的onemanager不是搭建在heroku上面,就填相同的域名就行了)。
复制下面代码到worker

// odd, 单日
const SingleDay = 'https://aaa1.herokuapp.com'
// even, 双日
const DoubleDay = 'https://bbb2.herokuapp.com'

//const SingleDay = 'https://153xxxxx0.cn-hongkong.fc.aliyuncs.com/2016-08-15/proxy/onedrive/xxx/'
//const DoubleDay = 'https://153xxxxx0.cn-hongkong.fc.aliyuncs.com/2016-08-15/proxy/onedrive/xxx/'

// CF proxy all, 一切给CF代理,true/false
const CFproxy = true

// Used in cloudflare workers, odd or even days point to 2 heroku account.

// 由于heroku不绑卡不能自定义域名,就算绑卡后https也不方便
// 另外免费套餐每月550小时,有些人不够用
// 于是在CF Workers使用此代码,分单双日拉取不同heroku帐号下的相同网页
// 只改上面,下面不用动

addEventListener('fetch', event => {
    let url=new URL(event.request.url);
    if (url.protocol == 'http:') {
        url.protocol = 'https:'
        event.respondWith( Response.redirect(url.href) )
    } else {
        let response = null;
        let nd = new Date();
        if (nd.getDate()%2) {
            host = SingleDay
        } else {
            host = DoubleDay
        }
        if (host.substr(0, 7)!='http://'&&host.substr(0, 8)!='https://') host = 'http://' + host;

        response = fetchAndApply(host, event.request);

        event.respondWith( response );
    }
})

async function fetchAndApply(host, request) {
    let f_url = new URL(request.url);
    let a_url = new URL(host);
    let replace_path = a_url.pathname;
    if (replace_path.substr(replace_path.length-1)!='/') replace_path += '/';
    let replaced_path = '/';
    let query = f_url.search;
    let path = f_url.pathname;
    if (host.substr(host.length-1)=='/') path = path.substr(1);
    f_url.href = host + path + query;

    let response = null;
    if (!CFproxy) {
        response = await fetch(f_url, request);
    } else {
        let method = request.method;
        let body = request.body;
        let request_headers = request.headers;
        let new_request_headers = new Headers(request_headers);
        new_request_headers.set('Host', f_url.host);
        new_request_headers.set('Referer', request.url);

        response = await fetch(f_url.href, {
            method: method,
            body: body,
            headers: new_request_headers
        });
    }

    let out_headers = new Headers(response.headers);
    if (out_headers.get('Content-Disposition')=='attachment') out_headers.delete('Content-Disposition');
    let out_body = null;
    let contentType = out_headers.get('Content-Type');
    if (contentType.includes("application/text")) {
        out_body = await response.text();
        while (out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
    } else if (contentType.includes("text/html")) {
        out_body = await response.text();
        while (replace_path!='/'&&out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
    } else {
        out_body = await response.body;
    }

    let out_response = new Response(out_body, {
        status: response.status,
        headers: out_headers
    })

    return out_response;
}

点击保存并部署
file
添加一条路由

file
file
将workers的域名填到onemanager的后台’domainforproxy’处
file

最后在域名处创建个cname,找到下面地址,填到cname里。。
file

使用onedrive搭建网盘https://xucg.info/2021/10/14/2584.html
THE END
分享
二维码
< <上一篇
下一篇>>