Skip to content

Commit

Permalink
support lanzou
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Nov 8, 2018
1 parent 7df5d0e commit 210e7b9
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 10 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data:
- user1:111111
- user2:aaaaaa
```
```basic```是内置的验证方式,使用用户名密码对进行判断,上面的例子中可使用```user1```的密码为```111```,```user2```的密码为```aaaaaa```。[请参考](blob/master/example/SecretFolder/.passwd)。
```basic```是内置的验证方式,使用用户名密码对进行判断,上面的例子中可使用```user1```的密码为```111```,```user2```的密码为```aaaaaa```。请参考[example/SecretFolder/.passwd](example)。

### 虚拟目录
在需创建虚拟目录处新建```目录名.d.ln```文件。 其内容为```挂载源:挂载路径```
Expand Down Expand Up @@ -86,7 +86,12 @@ ShareListDrive是ShareList内置的一种虚拟文件系统,使用yaml构建
#### OneDrive For Business
提供对OneDrive Business的访问。挂载标示odb,分享的url作为路径。
#### OpenLoad
提供对[OpenLoad](https://openload.co/)的访问。挂载标示openload,```ApiLogin:ApiKey@folderId```作为路径,省略@则从根目录开始列出文件。。
提供对[OpenLoad](https://openload.co/)的访问支持。挂载标示openload,```ApiLogin:ApiKey@folderId```作为路径,省略@则从根目录开始列出文件。
#### Lanzou蓝奏云
提供对[蓝奏云](https://www.lanzou.com/)的访问支持。挂载标示lanzou,```passwd@folderId```作为路径,无密码则直接使用```folderId```作为路径。
插件为目录 以及 mp4/jpg等禁止上传的格式提供解析支持。
对于文件,将```xxx.mp4```命名为```xxx.mp4.ct```后再上传,插件将自动解析为mp4文件。
对于目录,创建```目录名[email protected]```的文件上传即可。
### 插件开发
待完善
Expand Down Expand Up @@ -119,4 +124,3 @@ WebDAV 目录 `http://localhost:33001/webdav`
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/reruin/sharelist-heroku)



3 changes: 2 additions & 1 deletion app/services/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ const updateFolder = (folder) => {
return a.type == 'folder' && b.type != 'folder' ? -1 : a.type != 'folder' && b.type == 'folder' ? 1 : (a.$ - b.$)
})

}
return folder
}


/*
Expand Down
8 changes: 4 additions & 4 deletions app/services/sharelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ShareList {
const content = cache.get(pl, true)
if (content) {
console.log(`Get Cahce For Path(${pl})`)
return access_check(content)
return updateFolder(content)
}

if (pl == '') {
Expand All @@ -59,12 +59,12 @@ class ShareList {
// }else{
let children = parent.children || []
let index = base.search(children, 'name', curname)
//console.log('hit ' , index , curname)
if (index != -1) {
hit = children[index]
//只为目录做缓存
if (hit.type == 'folder')
if (hit.type == 'folder' && hit.id){
cache(pl, hit.protocol + ':' + hit.id)
}
} else {
return false
}
Expand Down Expand Up @@ -101,7 +101,6 @@ class ShareList {
if (hit.type == 'folder') {

resp = await vendor.folder(hit.id, { query, paths: diff(paths, full_paths), content: hit.content })

if (resp) updateFolder(resp)
//let passwd = base.checkPasswd(resp)
//resp.auth = passwd !== false
Expand All @@ -117,6 +116,7 @@ class ShareList {
else {
resp = await vendor.file(hit.id, hit)
// console.log( resp )
// 最终输出时更新文件操作
await updateFile(resp)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/utils/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ http.header = (url, opts) => {

http.get = (url, opts = {}) => {
let params = { ...opts }
params.headers = Object.assign({}, params.headers, headers)
params.headers = Object.assign({}, headers , params.headers || {})
params.url = url

if (debug) {
Expand All @@ -50,7 +50,7 @@ http.get = (url, opts = {}) => {

http.post = (url, form, opts) => {
let params = { ...opts }
params.headers = Object.assign({}, params.headers, headers)
params.headers = Object.assign({}, headers , params.headers || {})
params.url = url
params.form = form
params.method = 'POST'
Expand Down
1 change: 1 addition & 0 deletions example/lanzou.d.ln
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lanzou:b480558
158 changes: 158 additions & 0 deletions plugins/drive.lanzou.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* www.lanzous.com
* lanzou:password@foldId / foldId
*/

const name = 'Lanzous'

const version = '1.0'

const protocols = ['lanzou']

const defaultProtocol = 'lanzou'

const host = 'https://www.lanzous.com'

module.exports = ({ request , getConfig , datetime , cache }) => {

const parse = (id) => {
let tmp = id.split('@')
let passwd , fid
if( tmp.length == 2 ){
passwd = tmp[0]
fid = tmp[1]
}else if( tmp.length == 1){
fid = id
}
return { passwd , fid }
}

const getFormDataForFolder = (body) => {
let data = (body.match(/(?<=data\s*:\s*)\{.*?\}/) || [''])[0]
if( data ){
let formdata = {}

try{
let field_k = data.match(/(?<=\'k\':)[^\s,\}]+/)[0]
let field_t = data.match(/(?<=\'t\':)[^\s,\}]+/)[0]
let value_k = body.match(new RegExp('(?<='+field_k+"\\s*=\\s*')[^']+"))[0]
let value_t = body.match(new RegExp('(?<='+field_t+"\\s*=\\s*')[^']+"))[0] // timestamp
data = data.replace(new RegExp('(pgs|'+field_k+'|'+field_t+')','g'),'""').replace(/\'/g,'"').replace(/(?<=:)pwd/,'""')

formdata = JSON.parse( data )
formdata.k = value_k
formdata.t = value_t
delete formdata.pwd
return formdata
}catch(e){
return false
}

}else{
return false
}
}

const updateFile = (f) => {

if(f.name.endsWith('.d.txt')){
f.id = f.name.split('.').slice(-3,-2)[0]
f.name = f.name.split('.').slice(0,-3).join('.')
f.type = 'folder'
f.size = null
f.ext = null
}

return f
}

// gd folder => files
const folder = async(id) => {
let resid = `${defaultProtocol}:${id}`
let resp = false
let r = cache(resid)
if(r) {
resp = r
if(
resp.$cached_at &&
resp.children &&
( Date.now() - resp.$cached_at < getConfig().max_age_dir)

){
console.log('get folder from cache')
return resp
}
}

let params = parse(id)

if(params.fid){
let { body , headers } = await request.get(host+'/'+params.fid)
let cookie = headers['set-cookie'].join('; ')

let formdata = getFormDataForFolder(body)
if( formdata ){
formdata.pg = 1
if(params.passwd) {
formdata.pwd = params.passwd
}

let res = await request.post(`${host}/filemoreajax.php` , formdata ,{headers:{'Cookie':cookie} , json:true})

if( res.body && res.body.text){
resp = {id , type:'folder' , protocol:defaultProtocol}
let children = []

res.body.text.forEach( i => {
let name = i.name_all.replace(/\.ct$/,'')
let child = {
id:i.id,
name:name,
ext:name.split('.').pop(),
protocol:defaultProtocol,
// updated_at:datetime(i.upload_at*1000),
displaySize:i.size,
type : undefined,
}

children.push(updateFile({
id:i.id,
name:name,
ext:name.split('.').pop(),
protocol:defaultProtocol,
// updated_at:datetime(i.upload_at*1000),
displaySize:i.size,
type : undefined,
}))
})

//folder 额外保存
resp.children = children
resp.$cached_at = Date.now()

cache(resid,resp)
}
}

}

return resp
}

/**
* 获取文件实际路径
*/
const file = async(id , data = {}) =>{

let { body } = await request.get(`${host}/tp/${id}` , {headers:{'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; 1503-M02 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036558 Safari/537.36 MicroMessenger/6.3.25.861 NetType/WIFI Language/zh_CN'}})
let url = body.match(/(?<=submit\.href\s*=\s*urlpt\s*\+\s*')[^']+/)[0]
let base = body.match(/(?<=urlpt\s*=\s*')[^']+/)[0]
url = base + url
data.url = url
data.$cached_at = Date.now()
cache.save()
return data
}

return { name , version, drive:{ protocols, folder , file } }
}

0 comments on commit 210e7b9

Please sign in to comment.