-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package alias | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
|
||
"github.com/alist-org/alist/v3/internal/driver" | ||
"github.com/alist-org/alist/v3/internal/errs" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
"github.com/alist-org/alist/v3/pkg/utils" | ||
) | ||
|
||
type Alias struct { | ||
model.Storage | ||
Addition | ||
pathMap map[string][]string | ||
} | ||
|
||
func (d *Alias) Config() driver.Config { | ||
return config | ||
} | ||
|
||
func (d *Alias) GetAddition() driver.Additional { | ||
return &d.Addition | ||
} | ||
|
||
func (d *Alias) Init(ctx context.Context) error { | ||
if d.Paths == "" { | ||
return errors.New("paths is required") | ||
} | ||
d.pathMap = make(map[string][]string) | ||
for _, path := range strings.Split(d.Paths, "\n") { | ||
path = strings.TrimSpace(path) | ||
if path == "" { | ||
continue | ||
} | ||
k, v := getPair(path) | ||
d.pathMap[k] = append(d.pathMap[k], v) | ||
} | ||
return nil | ||
} | ||
|
||
func (d *Alias) Drop(ctx context.Context) error { | ||
d.pathMap = nil | ||
return nil | ||
} | ||
|
||
func (d *Alias) Get(ctx context.Context, path string) (model.Obj, error) { | ||
if utils.PathEqual(path, "/") { | ||
return &model.Object{ | ||
Name: "Root", | ||
IsFolder: true, | ||
Path: "/", | ||
}, nil | ||
} | ||
root, sub := getRootAndPath(path) | ||
dsts, ok := d.pathMap[root] | ||
if !ok { | ||
return nil, errs.ObjectNotFound | ||
} | ||
for _, dst := range dsts { | ||
obj, err := d.get(ctx, path, dst, sub) | ||
if err == nil { | ||
return obj, nil | ||
} | ||
} | ||
return nil, errs.ObjectNotFound | ||
} | ||
|
||
func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) { | ||
path := dir.GetPath() | ||
if utils.PathEqual(path, "/") { | ||
return d.listRoot(), nil | ||
} | ||
root, sub := getRootAndPath(path) | ||
dsts, ok := d.pathMap[root] | ||
if !ok { | ||
return nil, errs.ObjectNotFound | ||
} | ||
var objs []model.Obj | ||
for _, dst := range dsts { | ||
tmp, err := d.list(ctx, dst, sub) | ||
if err == nil { | ||
objs = append(objs, tmp...) | ||
} | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) { | ||
root, sub := getRootAndPath(file.GetPath()) | ||
dsts, ok := d.pathMap[root] | ||
if !ok { | ||
return nil, errs.ObjectNotFound | ||
} | ||
for _, dst := range dsts { | ||
link, err := d.link(ctx, dst, sub, args) | ||
if err == nil { | ||
return link, nil | ||
} | ||
} | ||
return nil, errs.ObjectNotFound | ||
} | ||
|
||
var _ driver.Driver = (*Alias)(nil) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package alias | ||
|
||
import ( | ||
"github.com/alist-org/alist/v3/internal/driver" | ||
"github.com/alist-org/alist/v3/internal/op" | ||
) | ||
|
||
type Addition struct { | ||
// Usually one of two | ||
// driver.RootPath | ||
// define other | ||
Paths string `json:"paths" required:"true" type:"text"` | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
var config = driver.Config{ | ||
Name: "Alias", | ||
LocalSort: true, | ||
NoCache: true, | ||
NoUpload: true, | ||
DefaultRoot: "/", | ||
} | ||
|
||
func init() { | ||
op.RegisterDriver(func() driver.Driver { | ||
return &Alias{} | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package alias |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package alias | ||
|
||
import ( | ||
"context" | ||
stdpath "path" | ||
"strings" | ||
|
||
"github.com/alist-org/alist/v3/internal/fs" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
"github.com/alist-org/alist/v3/pkg/utils" | ||
) | ||
|
||
func (d *Alias) listRoot() []model.Obj { | ||
var objs []model.Obj | ||
for k, _ := range d.pathMap { | ||
obj := model.Object{ | ||
Name: k, | ||
IsFolder: true, | ||
Modified: d.Modified, | ||
} | ||
objs = append(objs, &obj) | ||
} | ||
return objs | ||
} | ||
|
||
// do others that not defined in Driver interface | ||
func getPair(path string) (string, string) { | ||
//path = strings.TrimSpace(path) | ||
if strings.Contains(path, ":") { | ||
pair := strings.SplitN(path, ":", 2) | ||
if !strings.Contains(pair[0], "/") { | ||
return pair[0], pair[1] | ||
} | ||
} | ||
return stdpath.Base(path), path | ||
} | ||
|
||
func getRootAndPath(path string) (string, string) { | ||
path = strings.TrimPrefix(path, "/") | ||
parts := strings.SplitN(path, "/", 2) | ||
if len(parts) == 1 { | ||
return parts[0], "" | ||
} | ||
return parts[0], parts[1] | ||
} | ||
|
||
func (d *Alias) get(ctx context.Context, path string, dst, sub string) (model.Obj, error) { | ||
obj, err := fs.Get(ctx, stdpath.Join(dst, sub)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &model.Object{ | ||
Path: path, | ||
Name: obj.GetName(), | ||
Size: obj.GetSize(), | ||
Modified: obj.ModTime(), | ||
IsFolder: obj.IsDir(), | ||
}, nil | ||
} | ||
|
||
func (d *Alias) list(ctx context.Context, dst, sub string) ([]model.Obj, error) { | ||
objs, err := fs.List(ctx, stdpath.Join(dst, sub)) | ||
// the obj must implement the model.SetPath interface | ||
// return objs, err | ||
if err != nil { | ||
return nil, err | ||
} | ||
return utils.SliceConvert(objs, func(obj model.Obj) (model.Obj, error) { | ||
return &model.Object{ | ||
Name: obj.GetName(), | ||
Size: obj.GetSize(), | ||
Modified: obj.ModTime(), | ||
IsFolder: obj.IsDir(), | ||
}, nil | ||
}) | ||
} | ||
|
||
func (d *Alias) link(ctx context.Context, dst, sub string, args model.LinkArgs) (*model.Link, error) { | ||
link, _, err := fs.Link(ctx, stdpath.Join(dst, sub), args) | ||
return link, err | ||
} |
4 comments
on commit 301756b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不知道是否写完啦,现在经过测试 有几个疑问~
一、
现在似乎是只支持 根文件夹里面的二级文件夹
例如将两个 根文件夹路径写进去出现的还是两个没有合并的,
#No #OK
Paths Paths
/本地1 /本地1/本地
/本地2 /本地2/本地
#No #OK
/本地1 本地
/本地2
反正最后出现的文件夹名字一样就可以(最后结尾也不能是挂载时候显示的根文件夹)
就算是使用虚拟路径也不行QAQ 好像是还是会检测到是根文件夹 例如下面这样
#输入
/本地测试/本地1
/本地测试/本地2
#输出
/本地1
/本地2
二、
不同策略的方式不能组合在一起,否则无法播放,
例如:
- 默认302代理的阿里云盘和默认夸克云盘相同文件合并在一起了,在创建
alias
存储没有勾选
web代理(302播放)- 阿里云盘的可以播放,夸克的不可以
- 默认302代理的阿里云盘和默认夸克云盘相同文件合并在一起了,在创建
alias
存储勾选
web代理(本地代理播放)- 阿里可以播放,夸克也可以播放
302的优先权 大于 本地代理和代理URL链接
例如例2那样(查了一下F12会自动中转)
三、
如果是出现一样的文件合并后的
点击下载的时候调用是否是像负载均衡那样轮询的还是固定的QAQ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不知道是否写完啦,现在经过测试 有几个疑问~
一、 现在似乎是只支持 根文件夹里面的二级文件夹 例如将两个 根文件夹路径写进去出现的还是两个没有合并的,
#No #OK Paths Paths /本地1 /本地1/本地 /本地2 /本地2/本地
#No #OK /本地1 本地 /本地2
反正最后出现的文件夹名字一样就可以(最后结尾也不能是挂载时候显示的根文件夹)
就算是使用虚拟路径也不行QAQ 好像是还是会检测到是根文件夹 例如下面这样
#输入 /本地测试/本地1 /本地测试/本地2 #输出 /本地1 /本地2
二、 不同策略的方式不能组合在一起,否则无法播放, 例如:
默认302代理的阿里云盘和默认夸克云盘相同文件合并在一起了,在创建
alias
存储没有勾选
web代理(302播放)
- 阿里云盘的可以播放,夸克的不可以
默认302代理的阿里云盘和默认夸克云盘相同文件合并在一起了,在创建
alias
存储勾选
web代理(本地代理播放)
- 阿里可以播放,夸克也可以播放
302的优先权 大于 本地代理和代理URL链接
例如例2那样(查了一下F12会自动中转)三、 如果是出现一样的文件合并后的 点击下载的时候调用是否是像负载均衡那样轮询的还是固定的QAQ
- 你可以对路径重新命名
本地:/本地测试/本地1
本地:/本地测试/本地2
即可合并
2. 这个应该可以被修复,之后会修
3. 是固定的,取最前面的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
呃呃呃.... 抱歉 😭 😭 😭
我忘记了 哪个 在首页会出现一个新的
是我的锅
我忘记了我用虚拟路径的方式添加了一下.....
可以添加一个help提示302的不要和本地代理的混合在一起不然 本地代理的无法播放QAQ