forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drive.lb.js
54 lines (38 loc) · 1.14 KB
/
drive.lb.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
// 负载均衡器
const name = 'LoadBalancer'
const version = '1.0'
const protocols = ['lb']
const defaultProtocol = 'lb'
const rnd = (l) => {
let roll = Math.round( Math.random() * (l.length - 1) )
return l[roll].replace(/^\//,'')
}
module.exports = ({getConfig, setIgnorePaths , getDrives , getRuntime}) => {
const getCurrentPath = async (name) => {
let paths = await getDrives()
setIgnorePaths( 'lb' , paths.reduce((t,c) => t.concat( c.path.split(':')[1].split(';') ),[]) )
if(name){
let hit = paths.find( i => i.name == name)
if( hit ){
return rnd(hit.path.split(':')[1].split(';'))
}
}
}
getCurrentPath()
const folder = async() => {
let path = getRuntime('req').path
let rootName = path.replace(/^\//,'').split('/')[0]
let hit = await getCurrentPath(decodeURIComponent(rootName))
if( hit ){
path = path.replace(/^\/[^\/]+/,`/${(hit)}`)
return {
type:'redir',
name:rootName,
path:path
}
}else{
return false
}
}
return { name , label:'负载均衡', version , drive:{ protocols , folder , file : folder, cache:false} }
}