feat: get account files by path
This commit is contained in:
parent
164dab49ac
commit
2481676c46
@ -132,3 +132,49 @@ func GetAccountsByPath(path string) []driver.Driver {
|
|||||||
})
|
})
|
||||||
return accounts
|
return accounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAccountFilesByPath Obtain the virtual file generated by the account according to the path
|
||||||
|
// for example, there are: /a/b,/a/c,/a/d/e,/a/b.balance1,/av
|
||||||
|
// GetAccountFilesByPath(/a) => b,c,d
|
||||||
|
func GetAccountFilesByPath(prefix string) []driver.FileInfo {
|
||||||
|
files := make([]driver.FileInfo, 0)
|
||||||
|
accounts := make([]driver.Driver, len(accountsMap))
|
||||||
|
i := 0
|
||||||
|
for _, v := range accountsMap {
|
||||||
|
accounts[i] = v
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
sort.Slice(accounts, func(i, j int) bool {
|
||||||
|
if accounts[i].GetAccount().Index == accounts[j].GetAccount().Index {
|
||||||
|
return accounts[i].GetAccount().VirtualPath < accounts[j].GetAccount().VirtualPath
|
||||||
|
}
|
||||||
|
return accounts[i].GetAccount().Index < accounts[j].GetAccount().Index
|
||||||
|
})
|
||||||
|
prefix = utils.StandardizationPath(prefix)
|
||||||
|
set := make(map[string]interface{})
|
||||||
|
for _, v := range accounts {
|
||||||
|
// balance account
|
||||||
|
if strings.Contains(v.GetAccount().VirtualPath, balance) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
full := utils.StandardizationPath(v.GetAccount().VirtualPath)
|
||||||
|
if len(full) <= len(prefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// not prefixed with `prefix`
|
||||||
|
if !strings.HasPrefix(full, prefix+"/") && prefix != "/" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name := strings.Split(strings.TrimPrefix(strings.TrimPrefix(full, prefix), "/"), "/")[0]
|
||||||
|
if _, ok := set[name]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
files = append(files, model.File{
|
||||||
|
Name: name,
|
||||||
|
Size: 0,
|
||||||
|
Modified: v.GetAccount().Modified,
|
||||||
|
})
|
||||||
|
set[name] = nil
|
||||||
|
}
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user