Skip to content

Commit

Permalink
feat: lanzou folder secret
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Jul 10, 2020
1 parent 4d7553a commit 2de5c2d
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 169 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,12 @@ ShareList 是一个易用的网盘工具,支持快速挂载 GoogleDrive、OneD
挂载路径:
folderId
password@folderId
自定义路径如 s/aaa111
```
**注意:```folderId```是分享链接中```bxxxxxx```部分。**

插件为 ```mp4/jpg ```等禁止上传的格式提供解析支持,只需在文件名后附加```ct```后缀即可。以mp4为例,将```xxx.mp4```命名为```xxx.mp4.ct```后再上传,插件将自动解析为mp4文件。
插件为 ```mp4/jpg ```等禁止上传的格式提供解析支持,只需在文件名后附加```ct```后缀即可。以mp4为例,将```xxx.mp4```命名为```xxx.mp4.ct```后再上传,插件将自动解析为mp4文件。
插件可支持蓝奏自带的文件提取码功能。

***

Expand Down
11 changes: 5 additions & 6 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const os = require('os')
const { createFiledb } = require('./utils/db/filedb');
const configPath = process.cwd() +'/cache/config.json'
const port = process.env.PORT || 33001
const runtime = {}
var runtime = {}

const db = createFiledb(configPath , {raw:true} , {
port ,
Expand Down Expand Up @@ -82,8 +82,10 @@ const getAllConfig = (key) => db.all

const getPath = () => [].concat( db.get('path') || [] )

const getRuntime = (key) => {
return runtime[key]
const getRuntime = () => runtime

const setRuntime = (value) => {
runtime = value
}

const getSkin = (key) => {
Expand All @@ -107,9 +109,6 @@ const setPluginOption = (key , value) => {
db.save()
}

const setRuntime = (key , value) => {
runtime[key] = value
}

const saveDrive = (value , name) => {
if(!name) name = decodeURIComponent(runtime.req.path.replace(/^\//g,''))
Expand Down
4 changes: 2 additions & 2 deletions app/middleware/koa-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ module.exports = async(ctx, next) => {
}
let runtime = {
href:ctx.href,
path:ctx.path,
querystring:ctx.querystring,
query:ctx.query,
body:ctx.request.body,
Expand All @@ -84,6 +83,7 @@ module.exports = async(ctx, next) => {
paths:paths,
isAdmin,
access:ctx.session.access,
session:ctx.session,
...query
}
if( ctx.get('x-request') ){
Expand All @@ -106,7 +106,7 @@ module.exports = async(ctx, next) => {
}

ctx.runtime = runtime
setRuntime('req' , runtime)
setRuntime(runtime)
/*
setLocation({
href:ctx.href,
Expand Down
15 changes: 10 additions & 5 deletions app/services/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const recognize = async (image , type, lang) => {
const getSource = async (id , driverName , data) => {
if(driveMap.has(driverName)){
let vendor = getDrive(driverName)
let d = await vendor.file(id , { req: config.getRuntime('req') , data } )
let d = await vendor.file(id , { req: config.getRuntime() , data } )
if(d.outputType === 'file'){
return await getFile(d.url)
}
Expand Down Expand Up @@ -190,7 +190,7 @@ const getStream = async (ctx , id ,type, protocol , data) => {
const getPreview = async (data) => {
let ext = data.ext
let name = previewMap.get(ext)
return name ? await resources[name].preview[ext](data , config.getRuntime('req')) : null
return name ? await resources[name].preview[ext](data , config.getRuntime()) : null
}

const isPreviewable = async (data) => {
Expand Down Expand Up @@ -552,10 +552,15 @@ const getVendors = () => [...new Set(driveMountableMap.values())].map(id => {
})

const getAuth = (type) => {
if( authMap.has(type) ){
return resources[ authMap.get(type) ].auth[type]
let drive = getDrive(protocol)
if(drive.auth){
return drive.auth
}else{
return false
if( authMap.has(type) ){
return resources[ authMap.get(type) ].auth[type]
}else{
return false
}
}
}
//
Expand Down
37 changes: 25 additions & 12 deletions app/services/sharelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ShareList {
let currentPath
let data = await command('ls' , targetPath, (data , paths) => {
currentPath = '/' + paths.join('/')
if( this.hasPasswdFile(data) && req.access.has(currentPath) == false && !req.isAdmin) {
if( data.auth || (this.hasPasswdFile(data) && req.access.has(currentPath) == false && !req.isAdmin)) {
this.passwdPaths.add(currentPath)
// console.log(currentPath,true,req.access,encodeURIComponent(currentPath))
return true
Expand Down Expand Up @@ -151,17 +151,30 @@ class ShareList {
*/
async auth(req) {
let data = await command('ls' , req.paths.join('/'))
let hit = data.children.find(i => i.name == '.passwd')
let content = await getSource(hit.id, hit.protocol , hit)
let body = yaml.parse(content)
let auth = getAuth(body.type)
if (auth) {
let ra = await auth(req.body.user, req.body.passwd, body.data)
if(ra){
req.access.add(decodeURIComponent(req.path))
return true
}
}
// //自定义验证
// if(data.auth){
// let authHelper = getAuth(data.protocol)
// if(authHelper){
// let ra = await authHelper(data.id, req.body)
// if(ra){
// req.access.add(decodeURIComponent(req.path))
// return true
// }
// }
// }else{
let hit = data.children.find(i => i.name == '.passwd')
let content = await getSource(hit.id, hit.protocol , hit)
let body = yaml.parse(content)
let auth = getAuth(body.type)
if (auth) {
let ra = await auth(req.body.user, req.body.passwd, body.data)
if(ra){
req.access.add(decodeURIComponent(req.path))
return true
}
}
// }

return false
}

Expand Down
Loading

0 comments on commit 2de5c2d

Please sign in to comment.