forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drive.h5ai.js
82 lines (62 loc) · 1.73 KB
/
drive.h5ai.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* h5ai
* h5ai 列目录
*/
const name = 'h5ai'
const version = '1.0'
const protocols = ['h5ai']
const defaultProtocol = 'h5ai'
const path = require('path')
const { URL } = require("url")
const { Writable } = require('stream')
const clientMap = {}
module.exports = ({ request , getConfig, cache, base64 , retrieveSize, extname }) => {
const getContent = async (p) => {
let resp = await request.get(p)
const data = []
if( resp.body ){
resp.body.replace(/<tr><td.*?>(.*?)<\/td><td.*?><a.*?>(.*?)<\/a><\/td><td.*?>(.*?)<\/td><td.*?>(.*?)<\/td><\/tr>/g,($0,$1,$2,$3,$4) => {
if($0.indexOf('href=".."') == -1){
data.push({
type:$1.indexOf('folder') >=0 ? 'folder' : 'file',
filename:$2,
lastmod:$3,
size:retrieveSize($4),
})
}
})
}
return data
}
const folder = async (id) => {
//let [server , path] = id.split('>');
let resp = { id : id, type: 'folder', protocol: defaultProtocol }
let data = await getContent(id)
let children = [];
data.forEach(i => {
let path = (id + '/' + i.filename)
let obj = {
id: path,
name: i.filename,
protocol: defaultProtocol,
size: i.size,
created_at: i.lastmod,
updated_at: i.lastmod,
ext: extname(i.filename),
type: i.type
}
children.push(obj)
})
resp.$cached_at = Date.now()
resp.children = children
//cache.set(resid, resp)
return resp
}
const file = async (id , { data = {} } = {}) => {
data.url = id
// data.outputType = 'stream'
//data.proxy = 'stream'
return data
}
return { name, version, drive: { protocols, folder, file } }
}