diff --git a/README.md b/README.md index 4a91992f..73c08258 100644 --- a/README.md +++ b/README.md @@ -46,15 +46,12 @@ ShareList 是一个易用的网盘工具,支持快速挂载 GoogleDrive、OneD ``` 挂载标示:gda 挂载内容: - 文件(夹)id->应用ID|应用机钥|回调地址|refresh_token - 文件(夹)id->应用ID|应用机钥 + 文件(夹)id->应用ID|应用机钥|回调地址|refresh_token 文件(夹)id / ``` ShareList会根据填写的挂载内容的不同形式,自动开启挂载向导,按指示操作即可。 -特别提示:若不填写应用ID|应用机钥,向导将使用 [QuickStart](https://developers.google.com/drive/api/v3/quickstart/nodejs) 生成匿名应用,在授权验证过程中会出现```This app isn't verified.```,请以此点击```Advanced > Go to {Project Name} (unsafe).```即可出现正常的交互问询页面。 - ### 挂载OneDrive #### 1. 使用分享ID挂载 由[drive.od](plugins/drive.od.js)插件实现。 diff --git a/plugins/drive.gd.api.js b/plugins/drive.gd.api.js index db08db93..42531755 100644 --- a/plugins/drive.gd.api.js +++ b/plugins/drive.gd.api.js @@ -66,6 +66,11 @@ class oauth2ForGD { if (!appConfig) return { error: true, msg: '没有匹配到app_id' } let { client_id, client_secret, redirect_uri } = appConfig + + return await authToken({ client_id, client_secret, redirect_uri , code },key) + } + + async authToken({client_id, client_secret, redirect_uri , code} , key){ let params = { client_id, client_secret, @@ -73,7 +78,6 @@ class oauth2ForGD { code, grant_type: 'authorization_code' } - let resp try { resp = await this.request.post(this.OAUTH2_TOKEN_URL, params, { json: true }) @@ -85,7 +89,7 @@ class oauth2ForGD { let { refresh_token, expires_in, access_token } = resp.body this.clientMap[client_id] = { client_id, client_secret, redirect_uri, refresh_token, expires_in, access_token , update_time:Date.now() } - delete this.pathAppMap[key] + if(key) delete this.pathAppMap[key] await this.handleUpdate(this.clientMap[client_id]) return this.clientMap[client_id] @@ -158,18 +162,21 @@ const install = async (client_id, client_secret, redirect_uri) => { return `

挂载GoogleDrive

-

访问此链接创建应用,获取 应用机密 和 应用ID。

+

1. 访问此链接点击 [Enable the Drive API] 按钮,获取 credentials.json。如果你已有凭证请从第二步开开始。

-

或者 上传json凭证。

+

2. 上传json凭证。

+

3. 获取验证code

- - + +
+
` @@ -260,6 +290,30 @@ module.exports = ({ request, cache, getConfig, querystring, base64, saveDrive, g // 无credentials if(!credentials){ + + //使用 client_id, client_secret, code , redirect_uri 快速挂载 + if( req.body && req.body.act && req.body.act == 'quick_install'){ + let { client_id, client_secret, code , redirect_uri } = req.body + if (client_id && client_secret && code && redirect_uri) { + let credentials = await oauth2.authToken({client_id, client_secret, code , redirect_uri}) + if (credentials.error) { + return { + id, + type: 'folder', + protocol: defaultProtocol, + body: await error(credentials.msg, baseUrl) + } + } else { + return { + id, + type: 'folder', + protocol: defaultProtocol, + redirect: baseUrl + } + } + } + } + if (req.body && req.body.act && req.body.act == 'install') { let { client_id, client_secret, proxy_url } = req.body if (client_id && client_secret) { @@ -309,11 +363,14 @@ module.exports = ({ request, cache, getConfig, querystring, base64, saveDrive, g } // 缺少 refresh_token 跳转至验证页面 else{ - return { - id, - type: 'folder', - protocol: defaultProtocol, - redirect: await oauth2.generateAuthUrl({ ...credentials, redirect_uri: baseUrl }) + //校验redirect_uri 与当前连接是否一致 + if( credentials.redirect_uri == baseUrl ){ + return { + id, + type: 'folder', + protocol: defaultProtocol, + redirect: await oauth2.generateAuthUrl({ ...credentials, redirect_uri: baseUrl }) + } } } }