Skip to content

Commit

Permalink
fix: reruin#282
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Oct 3, 2020
1 parent 4d0a007 commit 54c2de5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ ShareList将自动开启挂载向导,按指示填写用户名密码即可。

### 虚拟目录
在需创建虚拟目录处新建```目录名.d.ln```文件。 其内容为```挂载标识:挂载路径```
指向本地```/root```的建虚拟目录
指向本地```/root```的虚拟目录
```
fs:/root
```
Expand All @@ -254,7 +254,7 @@ fs:/root
```
gd:0BwfTxffUGy_GNF9KQ25Xd0xxxxxxx
```
系统内置了一种单文件虚拟目录系统,使用yaml构建,以```sld```作为后缀保存。参考[example/ShareListDrive.sld](example/sharelist_drive.sld)
系统内置了一种单文件虚拟目录系统,使用yaml构建,以```sld.ln```作为后缀保存。参考[example/sharelist_drive.sld.ln](example/sharelist_drive.sld.ln)

***

Expand Down
2 changes: 1 addition & 1 deletion app/plugins/cmd.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ module.exports = ({ cache , getVendor , getConfig , getRuntime , updateFolder ,
}

if( hit.type == 'folder'){
let t = await vendor.folder(hit.id , { req : getRuntime('req')})
let t = await vendor.folder(hit.id , { content:hit.content, req : getRuntime('req')})
//console.log(t.type,t.children)
if( t ){
if( t.type == 'folder' ){
Expand Down
48 changes: 32 additions & 16 deletions app/plugins/drive.sld.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* xdrive 是 sharelist 内置的使用yaml描述的网盘系统 , 没有缓存
* xd: rootId(yaml文件所在路径) + yaml文件名 + ':' + 排序
*/

const name = 'ShareListDrive'
Expand All @@ -13,23 +12,35 @@ const defaultProtocol = 'xd'

const yaml = require('yaml')

const { URL } = require('url')

const crypto = require('crypto')

const md5 = (v) => {
return crypto.createHash('md5').update(v).digest('hex')
}

module.exports = ({isObject , isArray}) => {

const diskMap = {}

const getDisk = (id) => {
let [rootId , diskPath] = id.split('->')
const parse = (id) => {
let data = new URL(id)

let rootId = data.hostname
let path = data.pathname.replace(/^\/+/,'').split('/')
return {
disk:diskMap[rootId] ,
path:(diskPath || '').replace(/^\/+/,'').split('/')
path
}
}

/* 递归生成 索引 id */
const createId = (d, rootId) => {
d.forEach((i, index) => {
if (isObject(i)) {
i.id = rootId + '/' + i.name.replace(/\.d\.ln$/, '').replace(/\.ln$/, '')
let name = i.name.replace(/\.d\.ln$/, '').replace(/\.ln$/, '')
i.id = rootId + '/' + name
i.protocol = defaultProtocol
if (i.children) {
i.type = 'folder'
Expand All @@ -46,31 +57,36 @@ module.exports = ({isObject , isArray}) => {
return d
}

const mount = async (rootId, data) => {
let resp = { id: rootId, type: 'folder', protocol: defaultProtocol }
const mount = async (key,data) => {

if (data) {

let key = md5(data)

let id = defaultProtocol+'://'+key

let resp = { id, type: 'folder', protocol: defaultProtocol }

let json = yaml.parse(data)

json = createId(json, rootId + '->')
json = createId(json, id)
resp.children = json
resp.updated_at = Date.now()

diskMap[rootId] = resp

diskMap[key] = resp
return resp
} else {
return undefined
}
}

const findById = (id) => {
let { disk , path } = getDisk(id)
let { disk , path } = parse(id)
if(disk){
for (let i = 0; i < path.length && disk; i++) {
disk = disk.children
disk = disk.find(j => {
return `${j.name}` == path[i]
return j.name == decodeURIComponent(path[i])

if (j.type == 'folder') {
return `${j.name}.${j.ext}` == path[i]
Expand All @@ -86,10 +102,10 @@ module.exports = ({isObject , isArray}) => {
}
}

const folder = async (id, data) => {
if (data.content) {
return mount(id, data.content)
} else {
const folder = async (id,{ content } = {}) => {
if(content){
return mount(id,content)
}else{
return findById(id)
}
}
Expand Down
11 changes: 6 additions & 5 deletions app/services/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ const getSource = async (id , driverName , data) => {
return await parseStream( await vendor.createReadStream({id}) )
}
}
else if(d.content){
return d.content
}
else{
return await getHTTPFile(d.url , d.headers || {})
}
Expand Down Expand Up @@ -460,8 +463,7 @@ const updateFolder = (folder) => {
let ext = tmp[tmp.length-2]

//目录快捷方式 name.d.ln
let isDir = len > 2 && ext == 'd'

let isDir = (len > 2 && ext == 'd') || driveMap.has(ext)
if(isDir){
d.name = tmp.slice(0,-2).join('.')
d.type = 'folder'
Expand Down Expand Up @@ -509,12 +511,12 @@ const updateFolder = (folder) => {
* 调用解析器处理
*/
const updateLnk = async (d) => {

//获取快捷方式的指向内容
const content = await getSource(d.id , d.protocol)
//分析内容实体
const meta = parseLnk(content)
//从id中猜测协议

//包含协议时
if(meta){
d.protocol = meta.protocol
Expand All @@ -523,8 +525,7 @@ const updateLnk = async (d) => {
//不包含协议
else{
//从 id 猜测协议
let protocol = d.id.split('.').pop()

let protocol = d.id.replace(/\.ln/,'').split('.').pop()
if(driveMap.has(protocol)){
d.protocol = protocol
d.content = content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
name: SQL SERVER 2017 EXPRESS.exe
url: https://download.microsoft.com/download/5/E/9/5E9B18CC-8FD5-467E-B5BF-BADE39C51F73/SQLServer2017-SSEI-Expr.exe
-
name: 嵌套GoodleDrive虚拟目录@0B0vQvfdCBUFjdnRpVnZsWmlFanM.gd
name: 嵌套GoodleDrive虚拟目录.d.ln
content: gd:0B0vQvfdCBUFjdnRpVnZsWmlFanM
-
name: 嵌套windows本地D盘.d.ln
content: ld:/d/a.b
content: fs:/d/a.b
-
name: 嵌套linux root目录.d.ln
content: ld:/root
name: 嵌套linux 根目录.d.ln
content: fs:/

0 comments on commit 54c2de5

Please sign in to comment.