GoIndex - 无服务器架构 Google Drive 目录索引程序

前言

GoIndex 全称 Google Drive Directory Index,它是一款可以部署在 Cloudflare Workers 上的无服务器架构 ( Serverless ) Google Drive 目录索引程序,它可以将 Google Drive 文件以目录形式列出,并且可以通过直链进行下载,如果视频是 MP4 格式还可以在线观看。由于流量是通过 Cloudflare 中转,所以即使在被限制的网络环境下也能自由的使用。本篇教程讲解的是 GoIndex 使用自定义 API 部署的过程,理论上更安全且下载速度更快。

准备工作

打开 index.js 可以看到一些可以自由修改的参数。其中最后四项是需要我们手动去获取的参数。

    "siteName": "GoIndex", // 网站名称
    "root_pass": "index",  // 根目录密码,优先于.password
    "version" : "1.0.6", // 程序版本
    "theme" : "material", // material  classic 
    "client_id": "202264815644.apps.googleusercontent.com",
    "client_secret": "X4Z3ca8xfWDb1Voo-F9a7ZxJ",
    "refresh_token": "", // 授权 token
    "root": "root" // 根目录ID

获取 client_id 与 client_secret

  • 然后就可以看到客户端ID(client_id)和客户端密钥(client_secret),复制并保存好。

获取 refresh_token

  • 安装 Rclone
curl https://rclone.org/install.sh | bash
  • 输入rclone config命令,会出现以下信息,参照下面的注释进行操作。


点击查看

$ rclone config
...
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n  # 选择n,新建
name> gd
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Dropbox
   \ "dropbox"
10 / Encrypt/Decrypt a remote
   \ "crypt"
11 / FTP Connection
   \ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
15 / Hubic
   \ "hubic"
16 / JottaCloud
   \ "jottacloud"
17 / Koofr
   \ "koofr"
18 / Local Disk
   \ "local"
19 / Mail.ru Cloud
   \ "mailru"
20 / Mega
   \ "mega"
21 / Microsoft Azure Blob Storage
   \ "azureblob"
22 / Microsoft OneDrive
   \ "onedrive"
23 / OpenDrive
   \ "opendrive"
24 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
25 / Pcloud
   \ "pcloud"
26 / Put.io
   \ "putio"
27 / QingCloud Object Storage
   \ "qingstor"
28 / SSH/SFTP Connection
   \ "sftp"
29 / Transparently chunk/split large files
   \ "chunker"
30 / Union merges the contents of several remotes
   \ "union"
31 / Webdav
   \ "webdav"
32 / Yandex Disk
   \ "yandex"
33 / http Connection
   \ "http"
34 / premiumize.me
   \ "premiumizeme"
Storage> 13      # 选择 13 / Google Drive
** See help for drive backend at: https://rclone.org/drive/ **

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 string value. Press Enter for the default ("").
client_id> # 输入 客户端ID
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> # 输入 客户端密钥
Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 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 # 完整权限访问
ID of the root folder
Leave blank normally.

Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.

Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.

Enter a string value. Press Enter for the default ("").
root_folder_id> # 留空,回车
Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file> # 留空,回车
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n # 输入 n
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/XXXXXXX 
Log in and authorize rclone for access # 复制上面的链接到浏览器中打开进行授权。

在浏览器中你可能会遇到下图的提示,这是因为 API 是我们自己创建的,并没有通过 Google 的验证。

Enter verification code> # 在这里输入网页上显示的验证码
Configure this as a team drive?
y) Yes
n) No
y/n> y # 如果是团队盘输入 y ,否则输入 n
Fetching team drive list...
Choose a number from below, or type in your own value
 1 / P3TERX
   \ "0ADPHQ2hJ-6ZkUk9PVA"
Enter a Team Drive ID> 1 # 检测到团队盘,这里输入 1
2019/11/06 21:44:27 ERROR : Failed saving config "team_drive" = "0ADPHQ2hJ-6ZkUk9PVA" in section "gd" of the config file: section 'gd' not found
--------------------
[gd]
type = drive
client_id = 217429025371-pfu4k1ko34p4hku860kuj5k5v038f1u4.apps.googleusercontent.com
client_secret = 2VxOZcsItLFB8htDXDn2zl_e
scope = drive
token = {"access_token":"XXXXX","token_type":"Bearer","refresh_token":"1//0eDO2FT","expiry":"2019-11-06T22:44:23.013869707+08:00"} # 保存其中的 refresh_token
team_drive = 0ADPHQ2hJ-6ZkUk9PVA
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y # 输入 y 确认
Current remotes:

Name                 Type
====                 ====
Onedrive             onedrive
gd                   drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q # 输入 q 退出

获取根目录ID(root)

这里的根目录是指 GoIndex 显示的根目录,可以是你网盘中的任意目录。打开网盘定位到某个目录或共享目录,地址栏 URL 中最后面部分的代码就是目录ID了。如果是个人网盘参数留空则是网盘根目录。

创建 Workers

  • 新建一个 Workers 子域名。

    TIPS:后续无法更改,所以不要乱填。

  • 点击Create a Worker新建一个 Worker

  • 清空输入框中的内容,把修改好的 GoIndex 代码并粘贴进去,然后可以在左上角双击修改域名,再点击Save and Deploy即可。

  • 最后获取到的****.workers.dev就是你的 GoIndex 地址了,比如我的是gd.p3terx.workers.dev

自定义域名

  • 添加一个 CNAME 记录到前面获取到的地址。

  • 然后去 Workers 点击ADD route

  • 输入自定义域名,例如gd.p3terx.com/* 后面要加上/*,下面的 workers 选择刚才的项目。

  • 如果想要 http 自动跳转到 https 需要开启Always Use HTTPS

扩展玩法

如果你有谷歌云 VPS 可以通过 Aria2 下载并自动调用 Rclone 上传到谷歌网盘,谷歌云入站流量和谷歌自己服务的流量都是免费的,除了 BT 下载时上传会消耗一些收费流量外,其它几乎不会产生收费流量。GoIndex 在线观看或者下载到本地的数据走 Cloudflare 无需梯子,也不需要额外费用。如果你的谷歌网盘是无限盘就相当于0成本拥有了无限流量和无限空间的离线下载服务器和共享网盘。

相关阅读:《Aria2 + Rclone 实现 OneDrive、Google Drive 等网盘离线下载

参考资料

GoIndex - 一个无需服务器的Google Drive目录索引方案

GoIndex谷歌网盘神器,结合CloudFlare Workers

添加新评论

已有 2 条评论

emmm 总觉得这个主题的排版出来怪怪的,

自己又不会写主题,所以只能凑合用。