Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- No directory-level password protection(.password)
- Support Http Basic Auth
- Support multiple drives(personal, team) without changing server's code
- Support Aria2 download

## Usage

Expand All @@ -37,3 +38,37 @@ Go [https://gdindex-code-builder.glitch.me/](https://gdindex-code-builder.glitch
5. Copy the content of [worker/dist/worker.js](worker/dist/worker.js) to CloudFlare Workers.
6. Fill `refresh_token`, `root_folder_id` and other options on the top of the script.
7. Deploy!

### Enabling download with Aria2

1. Add config `download_aria2: true` to your `worker.js`:
```
default_root_id: '...',
client_id: '...',
client_secret: '...',
refresh_token: '...',
...
download_aria2: true
```
2. Redeploy, now you should see "Download with Aria2" and "Aria2 RPC Settings" beyond file list
3. Fill your aria2 connection info in "Aria2 RPC Settings"
4. Go to where you want to download and click "Download with aria2", which will add downloads for you!

### Enabling file copy on forbidden

Google Drive limited each users' file sharing bandwidth(about 750GB per day). If you try pulling a shared file from who exceed this limit, you will receive a `403 - forbidden` error. Copying file to your may solve this problem, but it hurts because you can only copy a file once a time.

That's why "Copy on forbidden" comes in.

1. Create a folder, which will be used to store your copied files, crawl its id from network requests(normally you can get it from Developer Tools)
2. Add following config to your `worker.js`:

```
...
copy_on_forbidden: true,
copy_parent_id: 'YOUR_COPY_FOLDER_ID' // replace YOUR_COPY_FOLDER_ID to your copy folder's ID
```

3. Just do normal download, if this file exceed limits, worker will make a copy and return copied one to you. This process is transparent so you won't need to deal other things.

Note: Be sure to delete all you copied files after a while, as more files get copied, it will consumer more space on you drive. Besides, this feature will NOT detect existing copies, multiple downloads will leads multiple copies.
35 changes: 35 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- 不支持目录加密(.password)
- 支持 Http Basic Auth
- 无需修改程序,即可接入多个云端硬盘(个人、团队)
- 支持导出 Aria2 下载

## 使用教学

Expand All @@ -33,3 +34,37 @@
5. 复制 [worker/dist/worker.js](worker/dist/worker.js) 的内容到 CloudFlare Workers
6. 在脚本顶端填上 `refresh_token`, `root_folder_id` 以及其他的选项
7. 部署!

### 启用 Aria2 下载

1. 在 `worker.js` 中添加配置 `download_aria2: true`:
```
default_root_id: '...',
client_id: '...',
client_secret: '...',
refresh_token: '...',
...
download_aria2: true
```
2. 重新部署,此时你应该可以在文件列表上方看到“使用 Aria2 下载”以及“Aria2 RPC 配置”两个按钮
3. 在“Aria2 RPC 配置”中填写 Aria2 RPC 连接信息
4. 前往你要下载的文件夹,点击“使用 Aria2 下载”,开始添加下载任务

### 启用按需复制

Google Drive 限制了每个用户分享文件的流量(一般是每天 750GB)。如果你试图从超出流量限制的用户处下载一个分享文件,会收到 `403 - forbidden` 错误。将文件复制一份可能可以解决此问题,但是在网页端上一次操作只能复制一个文件。

因此,我们引入了“按需复制”功能。

1. 新建一个用于存放所有复制文件的文件夹。打开“开发者工具”获得这个文件夹的 ID
2. 添加以下配置到你的 `worker.js`:

```
...
copy_on_forbidden: true,
copy_parent_id: 'YOUR_COPY_FOLDER_ID' // 替换 YOUR_COPY_FOLDER_ID 为你的文件夹 ID
```

3. 正常开始下载即可,如果 worker 检测到文件分享流量超出限制,会自动复制一份到之前的文件夹并返回复制的文件给你。该过程是透明的,因此你无需进行额外处理

注意:请在下载完一段时间后删除复制的文件,否则,随着复制的文件越多,它们会占用更多的空间。另外,复制过程中不会检测是否已有复制的文件,因此多次下载会触发多次复制动作。
35 changes: 35 additions & 0 deletions README.zhtw.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- 不支援目錄加密(.password)
- 支援 Http Basic Auth
- 支援多雲端硬碟(個人、團隊),不需要額外改程式設定
- 支援通過 Aria2 下載

## 使用教學

Expand All @@ -33,3 +34,37 @@
5. 複製 [worker/dist/worker.js](worker/dist/worker.js) 的內容到 CloudFlare Workers
6. 在腳本頂端填上 `refresh_token`, `root_folder_id` 以及其他的選項
7. 部署!

### 啟用 Aria2 下載

1. 在 `worker.js` 中添加配置 `download_aria2: true`:
```
default_root_id: '...',
client_id: '...',
client_secret: '...',
refresh_token: '...',
...
download_aria2: true
```
2. 重新部署,此時你應該可以在文件列表上方看到“使用 Aria2 下載”以及“Aria2 RPC 配置”兩個按鈕
3. 在“Aria2 RPC 配置”中填寫 Aria2 RPC 連接信息
4. 前往你要下載的文件夾,點擊“使用 Aria2 下載”,開始添加下載任務

### 啟用按需複制

Google Drive 限制了每個用戶分享文件的流量(一般是每天 750GB)。如果你試圖從超出流量限制的用戶處下載一個分享文件,會收到 `403 - forbidden` 錯誤。將文件複製一份可能可以解決此問題,但是在網頁端上一次操作只能複制一個文件。

因此,我們引入了“按需複制”功能。

1. 新建一個用於存放所有復製文件的文件夾。打開“開發者工具”獲得這個文件夾的 ID
2. 添加以下配置到你的 `worker.js`:

```
  ...
  copy_on_forbidden: true,
  copy_parent_id: 'YOUR_COPY_FOLDER_ID' // 替換 YOUR_COPY_FOLDER_ID 為你的文件夾 ID
```

3. 正常開始下載即可,如果 worker 檢測到文件分享流量超出限制,會自動複製一份到之前的文件夾並返回複製的文件給你。該過程是透明的,因此你無需進行額外處理

注意:請在下載完一段時間後刪除複製的文件,否則,隨著複製的文件越多,它們會佔用更多的空間。另外,複製過程中不會檢測是否已有復制的文件,因此多次下載會觸發多次復制動作。
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"aria2": "^4.1.0",
"core-js": "^2.6.5",
"date-fns": "^2.4.1",
"inline-resource": "^0.1.7",
Expand Down
92 changes: 92 additions & 0 deletions web/src/aria2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// a simple module provides aria2 supports

import Aria2 from 'aria2'

const KEY_ARIA2_RPC_HOST = 'ARIA2_RPC_HOST'
const KEY_ARIA2_RPC_PORT = 'ARIA2_RPC_PORT'
const KEY_ARIA2_RPC_PATH = 'ARIA2_RPC_PATH'
const KEY_ARIA2_RPC_TOKEN = 'ARIA2_RPC_TOKEN'
const KEY_ARIA2_DOWNLOAD_PATH = 'ARIA2_DOWNLOAD_PATH'

function getStringFromLocalStorage(key, defaultValue) {
return localStorage.getItem(key) || defaultValue
}

function setStringToLocalStorage(key, value) {
return localStorage.setItem(key, value)
}

const aria2Support = {
aria2: null,
getRpcHost: function() {
return getStringFromLocalStorage(KEY_ARIA2_RPC_HOST)
},
setRpcHost: function(host) {
return setStringToLocalStorage(KEY_ARIA2_RPC_HOST, host)
},
getRpcPort: function() {
let port = getStringFromLocalStorage(KEY_ARIA2_RPC_PORT)
if (!port) {
port = 6800
}
return port
},
setRpcPort: function(port) {
if (Number.isNaN(Number(port))) {
return false
}

return setStringToLocalStorage(KEY_ARIA2_RPC_PORT, port)
},
getRpcPath: function() {
return getStringFromLocalStorage(KEY_ARIA2_RPC_PATH, '/jsonrpc')
},
setRpcPath: function(path) {
return setStringToLocalStorage(KEY_ARIA2_RPC_PATH, path)
},
getRpcToken: function() {
return getStringFromLocalStorage(KEY_ARIA2_RPC_TOKEN)
},
setRpcToken: function(token) {
return setStringToLocalStorage(KEY_ARIA2_RPC_TOKEN, token)
},
getDownloadPath: function() {
return getStringFromLocalStorage(KEY_ARIA2_DOWNLOAD_PATH)
},
setDownloadPath: function(path) {
return setStringToLocalStorage(KEY_ARIA2_DOWNLOAD_PATH, path)
},
prepare: function() {
if (this.aria2) {
return
}

const options = {
host: this.getRpcHost(),
port: this.getRpcPort(),
secure: false,
secret: this.getRpcToken(),
path: this.getRpcPath()
}
this.aria2 = new Aria2(options)
},
test: async function() {
if (!this.aria2) {
this.prepare()
}

return await this.aria2.call('getVersion')
},
addDownload: async function(url, downloadPath) {
if (!this.aria2) {
this.prepare()
}
const option = {
dir: downloadPath
}

return await this.aria2.call('addUri', [url], option)
}
}

export default aria2Support
Loading