Skip to content

Conversation

Seven66677731
Copy link
Contributor

@Seven66677731 Seven66677731 commented Aug 22, 2025

添加strm文件至本地
使用方式打开开关,填写本地目标路径
image

触发条件:访问strm驱动中对应目录或刷新被 strm 驱动挂载的路径
close: #1044

@tangxl0604

This comment was marked as off-topic.

Copilot

This comment was marked as outdated.

@tangxl0604

This comment was marked as off-topic.

@ILoveScratch2

This comment was marked as resolved.

@tangxl0604

This comment was marked as spam.

@tangxl0604

This comment was marked as off-topic.

@ILoveScratch2

This comment was marked as outdated.

@Seven66677731

This comment was marked as resolved.

@tangxl0604

This comment was marked as off-topic.

@RedSTARO

This comment was marked as off-topic.

@Seven66677731 Seven66677731 marked this pull request as draft September 5, 2025 06:20
@Seven66677731 Seven66677731 marked this pull request as ready for review September 5, 2025 08:22
@tangxl0604

This comment was marked as spam.

@ILoveScratch2 ILoveScratch2 requested a review from xrgzs September 15, 2025 11:28
@OpenListTeam OpenListTeam deleted a comment from tangxl0604 Sep 15, 2025
@OpenListTeam OpenListTeam deleted a comment from tangxl0604 Sep 15, 2025
@tangxl0604

This comment was marked as spam.

@tangxl0604

This comment was marked as spam.

Comment on lines +26 to +31
for id := range strmMap {
strmDriver := strmMap[id]
if !strmDriver.SaveStrmToLocal {
continue
}
for _, path := range strings.Split(strmDriver.Paths, "\n") {
Copy link
Contributor

@KirCute KirCute Sep 21, 2025

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})
Copy link
Contributor

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的调用

Copy link
Contributor Author

@Seven66677731 Seven66677731 Sep 22, 2025

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{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该会有问题,部分网盘需要从args里读取参数,例如115会读取User-Agent

Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是在downloadSuffix类型下的文件,这里MFile会出现空的问题?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,这里应该使用stream.NewSeekableStreamlink转为流,而不是直接使用link.MFile

@Seven66677731 Seven66677731 marked this pull request as draft September 27, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] 增加strm 本地挂载
7 participants