Skip to content

Commit

Permalink
docs: Kubesail
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Aug 4, 2020
1 parent 22c1b3c commit fc2dff5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,7 @@ WebDAV 目录 `http://localhost:33001/webdav`
### Heroku

[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/reruin/sharelist-heroku)

### Kubesail

[![Deploy](https://img.shields.io/badge/deploy%20to-kubesail-blue?style=for-the-badge)](https://kubesail.com/template/reruin/sharelist)
2 changes: 1 addition & 1 deletion plugins/drive.189cloud.business.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Manager {
if (hit) {
return { ...hit, path: data.path }
} else {
return { error: '挂在失败,请确保账号或者密码正确' }
return { error: '挂载失败,请确保账号或者密码正确' }
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/drive.189cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Manager {
if(hit){
return { ...hit, path:data.path }
}else{
return { error:'挂在失败,请确保账号或者密码正确' }
return { error:'挂载失败,请确保账号或者密码正确' }
}
}

Expand Down
64 changes: 42 additions & 22 deletions plugins/drive.caiyun.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ class Manager {
let hit = this.clientMap[data.username]
if(hit){
if( !hit.cookie || (Date.now() - hit.updated_at) > COOKIE_MAX_AGE ){
let { result , msg } = await this.create(hit.username , hit.password)
let { result , msg , ...rest } = await this.create(hit.username , hit.password)
if( result ){
hit = this.clientMap[data.username]
}else{
return { error: msg }
return { error: msg, ...rest }
}
}
}
Expand All @@ -153,7 +153,7 @@ class Manager {
let p = (data.path == '/' || data.path == '') ? '00019700101000000001' : data.path
return { ...hit, path:p }
}else{
return { error:'挂在失败,请确保账号或者密码正确' }
return { error:'挂载失败,请确保账号或者密码正确' }
}
}

Expand Down Expand Up @@ -185,9 +185,17 @@ class Manager {
})
}

hasCaptchaTask(id){
return id in this.captchaProcess
}

async resumeCaptchaTask(id , captcha){
let {username , password} = this.captchaProcess[id]
return await this.create(username , password,id , captcha)
}

//create cookie
async create(username , password, captchaId, captcha){

let publicKeyExponent, publicKeyModulus, cookie
let needcaptcha = false, retry = 0
if( captchaId && this.captchaProcess[captchaId]){
Expand Down Expand Up @@ -220,7 +228,10 @@ class Manager {
'encodeType':'1',
'validate':'',//验证码
}
if( captcha ) formdata.validate = captcha
if( captcha ) {
formdata.validate = captcha
formdata.hidden_verfycode = 'true'
}
let result = false
let msg = ''

Expand All @@ -245,7 +256,7 @@ class Manager {
}
if(retry <= 0){
let key = captchaId || Math.random()
this.captchaProcess[key] = { publicKeyExponent,publicKeyModulus,cookie }
this.captchaProcess[key] = { username,password,publicKeyExponent,publicKeyModulus,cookie }
return { result:false , custom:{key , img:imgBase64} }
}
retry--
Expand Down Expand Up @@ -288,7 +299,6 @@ class Manager {
async:true,
followRedirect:false
})

if(resp.headers && resp.headers['location']){
let success = false , code
try{
Expand Down Expand Up @@ -374,6 +384,20 @@ module.exports = ({ request, cache, getConfig, querystring, base64, saveDrive, g
manager.init(resp)
})

const afterPrepare = async (data = {},id,req) => {
let { result , msg , custom } = data
if( result ){
return { id, type: 'folder', protocol: defaultProtocol,redirect: req.origin + req.path }
}else{
if( custom ){
return { id, type: 'folder', protocol: defaultProtocol,body: await captchaPage({username:data.username,password:data.password,...custom}) }
}
else {
return { id, type: 'folder', protocol: defaultProtocol,body: await install(msg || '请确认账号密码正确') }
}
}
}

const prepare = async (id) => {
if(!id.startsWith(defaultProtocol)){
id = defaultProtocol + ':' + id
Expand All @@ -382,26 +406,23 @@ module.exports = ({ request, cache, getConfig, querystring, base64, saveDrive, g

let baseUrl = req.origin + req.path

let { path, cookie, username, error } = await manager.get(id)
//验证码
if( req.body && req.body.key && req.body.captcha && manager.hasCaptchaTask(req.body.key)){
return await afterPrepare(await manager.resumeCaptchaTask(req.body.key,req.body.captcha ),id , req)
}

if( cookie ) {
let { path, cookie, username, password, error , custom } = await manager.get(id)

if( cookie ) {
return { cookie , path , username }

}else{
if (req.body && req.body.username && req.body.password && req.body.act == 'install') {
let { username, password,key,captcha} = req.body
let { result , msg , custom } = await manager.create(username , password,key,captcha)
if( result ){
return { id, type: 'folder', protocol: defaultProtocol,redirect: req.origin + req.path }
}else{
if( custom ){
return { id, type: 'folder', protocol: defaultProtocol,body: await captchaPage({username,password,...custom}) }
}
else {
return { id, type: 'folder', protocol: defaultProtocol,body: await install(msg || '请确认账号密码正确') }
}
}
let data = await manager.create(username , password,key,captcha)
return await afterPrepare(data,id , req)
}
else if(custom){
return { id, type: 'folder', protocol: defaultProtocol,body: await captchaPage({username,password,...custom}) }
}

return { id, type: 'folder', protocol: defaultProtocol,body: await install(error) }
Expand Down Expand Up @@ -505,7 +526,6 @@ module.exports = ({ request, cache, getConfig, querystring, base64, saveDrive, g
// 无临时链接 强制中转
const file = async (id, options) => {
let predata = await prepare(id)

if (!predata.cookie) return predata

let { path, cookie , username } = await prepare(id)
Expand Down
2 changes: 1 addition & 1 deletion plugins/preview.media.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ module.exports = ({getSource , getPluginOption , setPluginOption , getConfig}) =
});

return { name , version , preview }
}
}

0 comments on commit fc2dff5

Please sign in to comment.