CloudFlare Workers 代理 Google Drive
CloudFlare Workers 架设 Google Drive 目录,实现国内永久直链访问
介绍
众所周知Google Drive
是被墙的,而通过CloudFlare
代理链接可实现国内访问Google Drive
服务,本文介绍如何搭建Google Drive
文件索引
结合 Cloudflare Workers 和 Google Drive 的力量,可以在Cloudflare Workers的浏览器上建立你的文件索引
项目地址: goindex-theme-acrou
部署
创建 Google 项目
跳转
创建项目
页面,输入项目名
之后确认创建
接着会跳转到OAuth 同意屏幕
,User Type
选择外部
修改应用注册,必填项为应用名称
、用户支持电子邮件
以及底下的开发者联系信息
,其他可不填,保存即可
接下来的测试用户
添加自己的邮箱即可
开启 Google Drive API
跳转 开启 Google Drive API 页面,开启该功能
开启成功后如下
创建 OAuth client ID
跳转
创建 OAuth client ID
页面,应用类型
选择桌面应用
,名称
随意,完成后点击创建
创建成功会返回客户端 ID
和客户端密钥
,自行保存,后面需要用到
安装 Rclone
下载地址 ,根据自己的系统版本选择下载之后解压
CMD 运行 Rclone
有两种方法,就Win10系统举例
- 在
Rclone
解压的目录的地址栏输入cmd
,打开当前路径的命令行终端 - 在系统环境变量
Path
添加Rclone
的路径
在之后获取
Google Drive
的refresh token
时需要访问到
但CMD
默认是不走代理的
可自行设置临时代理
set http_proxy=http://ip:port
set https_proxy=http://ip:port
使用 Rclone 获取 refresh_token
在终端上执行rclone config
,n
新建,名字随意
$ rclone config
No remotes found, make a new one? n) New remote s) Set configuration password q) Quit config n/s/q> n
Enter name for new remote. name> GoIndex
选择18
即Google Drive
Option Storage. Type of storage to configure. Choose a number from below, or type in your own value.
...
17 / Google Cloud Storage (this is not Google Drive) \ (google cloud storage) 18 / Google Drive \ (drive) 19 / Google Photos \ (google photos)
...
Storage> 18
之后填写先前获取的client id
和client secret
,scope
权限选择1
,即所有权限
service_account_file
回车不填即可
Edit advanced config
也是回车默认No
Option client_id. Google Application Client Id Setting your own is recommended. See https://rclone.org/drive/#making-your-own-client-id for how to create your own. If you leave this blank, it will use an internal key which is low performance. Enter a value. Press Enter to leave empty. client_id> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
Option client_secret. OAuth Client Secret. Leave blank normally. Enter a value. Press Enter to leave empty. client_secret> xxxxxxxxxxxxxxxxxxx
Option scope.
Scope that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
1 / Full access all files, excluding Application Data Folder.
\ (drive)
2 / Read-only access to file metadata and file contents.
\ (drive.readonly)
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ (drive.file)
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
\ (drive.appfolder)
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
\ (drive.metadata.readonly)
scope> 1
Use auto config
选择n
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> n
之后就会提示输入验证码,复制rclone authorize "drive" "xxx"
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
rclone authorize "drive" "xxx"
Then paste the result.
Enter a value.
config_token>
开启另外一个终端执行复制的命令,记得先开代理哦
之后会跳转到浏览器,登录并授权
显示如下即代表成功获取
回到终端复制返回的验证码,并在第一个终端输入
Paste the following into your remote machine --->
此段为验证码
<---End paste
根据自己的盘是不是Team Drive
选择,得到的token
里就有我们需要的refresh_token
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> n
Configuration complete.
Options:
- type: drive
- client_id: 642717824648-vv6fp0441ldalr9um9jqdftu49lisacu.apps.googleusercontent.com
- client_secret: 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
- scope: drive
- token: {"access_token":"xxx","token_type":"Bearer","refresh_token":"xxx","expiry":"20xx-xx-xxTxx:xx:xx.xxxxxxx+xx:xx"}
获取GoIndex
替换
index.js
里的client_id
,client_secret
,refresh_token
为自己的
部署到 CloudFlare Workers
前往 CloudFlare
到Workers
页面下,创建服务
点击快速编辑
,将内容替换为刚才修改后的index.js
,保存并部署
默认访问的路径有
TeamDrive
,PrivateDrive
和folder1
可按需删除或移动顺序,也可设置访问的账号密码,第一个为默认访问
roots: [
{
id: "",
name: "TeamDrive",
pass: "",
},
{
id: "root",
name: "PrivateDrive",
user: "",
pass: "",
protect_file_link: true,
},
{
id: "",
name: "folder1",
pass: "",
},
],
其他个性化设置可参考 README