-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(strm): strm local file #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
for id := range strmMap { | ||
strmDriver := strmMap[id] | ||
if !strmDriver.SaveStrmToLocal { | ||
continue | ||
} | ||
for _, path := range strings.Split(strmDriver.Paths, "\n") { |
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.
这里二重循环效率不是很高的样子,能不能用前缀树优化,例如:
var strmMap = patricia.NewTrie()
func UpdateLocalStrm(ctx context.Context, parent string, objs []model.Obj) {
_ = strmMap.VisitPrefixes(patricia.Prefix(parent), func(prefix patricia.Prefix, item patricia.Item) error {
path := string(prefix)
rest := strings.TrimPrefix(parent, path)
if rest[0] != "/" {
return nil
}
strmDrivers := item.([]*Strm)
// TODO Update here
})
}
func InsertStrm(dstPath string, d *Strm) error {
prefix := patricia.Prefix(dstPath)
l := strmMap.Get(prefix)
if l == nil {
if !strmMap.Insert(prefix, []*Strm{d}) {
return errors.New("failed")
}
return nil
}
strmMap.Set(prefix, append(l, d))
return nil
}
func RemoveStrm(dstPath string, d *Strm) {
prefix := patricia.Prefix(dstPath)
l := strmMap.Get(prefix)
if l == nil {
return
}
if len(l) == 1 && l[0] == d {
strmMap.Delete(prefix)
return
}
for i, di := range l {
if di == d {
strmMap.Set(prefix, append(l[:i], l[i+1:]...))
return
}
}
}
func (d *Strm) Init(ctx context.Context) error {
// ...
for _, path := range strings.Split(d.Paths, "\n") {
err := InsertStrm(utils.FixAndCleanPath(strings.TrimSpace(path)), d)
if err != nil {
return err
}
}
}
func (d *Strm) Drop(ctx context.Context) error {
for _, path := range strings.Split(d.Paths, "\n") {
RemoveStrm(utils.FixAndCleanPath(strings.TrimSpace(path)), d)
}
}
其中patricia
来自github.com/tchap/go-patricia/v2/patricia
这个库
strmPath := path[strings.LastIndex(path, "/"):] | ||
relPath := stdpath.Join(strmDriver.MountPath, strmPath, strings.TrimPrefix(parent, path)) | ||
if len(relPath) > 0 { | ||
_, _ = fs.List(ctx, relPath, &fs.ListArgs{Refresh: false, NoLog: true}) |
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.
这里调用strm的List,会不会出现strm又重新调用List导致这里的更新逻辑又重来一遍?
我觉得如果能直接在这个位置充分利用objs
形参进行strm驱动的更新会更好一些,如果我理解的没错的话,这样做至少也能减少一次后端驱动API的调用
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.
最近比较忙,有时间我再看看
if obj.IsDir() { | ||
continue | ||
} | ||
link, linkErr := d.Link(ctx, obj, model.LinkArgs{}) |
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.
这里应该会有问题,部分网盘需要从args里读取参数,例如115会读取User-Agent
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.
Copy
在类似环节也传的空LinkArgs
,应该没有问题
// call hooks | ||
go func(reqPath string, files []model.Obj) { | ||
HandleObjsUpdateHook(reqPath, files) | ||
HandleObjsUpdateHook(ctx, reqPath, files) |
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.
这个ctx由于异步调用会出现context canceled的问题
log.Errorf("create nested file failed, %s", createErr) | ||
continue | ||
} | ||
_, copyErr := io.Copy(file, link.MFile) |
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.
如果是在downloadSuffix类型下的文件,这里MFile会出现空的问题?
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.
确实,这里应该使用stream.NewSeekableStream
将link
转为流,而不是直接使用link.MFile
添加strm文件至本地

使用方式打开开关,填写本地目标路径
触发条件:访问strm驱动中对应目录或刷新被 strm 驱动挂载的路径
close: #1044