mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-02 21:27:15 +08:00
support file name auto complete input
This commit is contained in:
parent
4782cec115
commit
c1cb3a60dd
49
internal/config/cache.go
Normal file
49
internal/config/cache.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
||||||
|
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
||||||
|
"github.com/tickstep/library-go/expires"
|
||||||
|
"path"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// deleteCache 删除含有 dirs 的缓存
|
||||||
|
func (pu *PanUser) deleteCache(dirs []string) {
|
||||||
|
cache := pu.cacheOpMap.LazyInitCachePoolOp(pu.ActiveDriveId)
|
||||||
|
for _, v := range dirs {
|
||||||
|
key := v + "_" + "OrderByName"
|
||||||
|
_, ok := cache.Load(key)
|
||||||
|
if ok {
|
||||||
|
cache.Delete(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CacheFilesDirectoriesList 缓存获取
|
||||||
|
func (pu *PanUser) CacheFilesDirectoriesList(pathStr string) (fdl aliyunpan.FileList, apiError *apierror.ApiError) {
|
||||||
|
data := pu.cacheOpMap.CacheOperation(pu.ActiveDriveId, pathStr+"_OrderByName", func() expires.DataExpires {
|
||||||
|
var fi *aliyunpan.FileEntity
|
||||||
|
fi, apiError = pu.panClient.FileInfoByPath(pu.ActiveDriveId, pathStr)
|
||||||
|
if apiError != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
fileListParam := &aliyunpan.FileListParam{
|
||||||
|
DriveId: pu.ActiveDriveId,
|
||||||
|
ParentFileId: fi.FileId,
|
||||||
|
}
|
||||||
|
fdl, apiError = pu.panClient.FileListGetAll(fileListParam)
|
||||||
|
if apiError != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// construct full path
|
||||||
|
for _, f := range fdl {
|
||||||
|
f.Path = path.Join(pathStr, f.FileName)
|
||||||
|
}
|
||||||
|
return expires.NewDataExpires(fdl, 1*time.Minute)
|
||||||
|
})
|
||||||
|
if apiError != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return data.Data().(aliyunpan.FileList), nil
|
||||||
|
}
|
@ -17,6 +17,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
||||||
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
||||||
|
"github.com/tickstep/library-go/expires/cachemap"
|
||||||
"github.com/tickstep/library-go/logger"
|
"github.com/tickstep/library-go/logger"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -47,6 +48,7 @@ type PanUser struct {
|
|||||||
WebToken aliyunpan.WebLoginToken `json:"webToken"`
|
WebToken aliyunpan.WebLoginToken `json:"webToken"`
|
||||||
|
|
||||||
panClient *aliyunpan.PanClient
|
panClient *aliyunpan.PanClient
|
||||||
|
cacheOpMap cachemap.CacheOpMap
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanUserList []*PanUser
|
type PanUserList []*PanUser
|
||||||
|
62
main.go
62
main.go
@ -213,13 +213,13 @@ func main() {
|
|||||||
var (
|
var (
|
||||||
activeUser = config.Config.ActiveUser()
|
activeUser = config.Config.ActiveUser()
|
||||||
runeFunc = unicode.IsSpace
|
runeFunc = unicode.IsSpace
|
||||||
//cmdRuneFunc = func(r rune) bool {
|
cmdRuneFunc = func(r rune) bool {
|
||||||
// switch r {
|
switch r {
|
||||||
// case '\'', '"':
|
case '\'', '"':
|
||||||
// return true
|
return true
|
||||||
// }
|
}
|
||||||
// return unicode.IsSpace(r)
|
return unicode.IsSpace(r)
|
||||||
//}
|
}
|
||||||
targetPath string
|
targetPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -248,12 +248,54 @@ func main() {
|
|||||||
if isAbs {
|
if isAbs {
|
||||||
targetDir = path.Dir(targetPath)
|
targetDir = path.Dir(targetPath)
|
||||||
} else {
|
} else {
|
||||||
targetDir = path.Join(activeUser.Workdir, targetPath)
|
wd := "/"
|
||||||
|
if activeUser.IsFileDriveActive() {
|
||||||
|
wd = activeUser.Workdir
|
||||||
|
} else if activeUser.IsAlbumDriveActive() {
|
||||||
|
wd = activeUser.AlbumWorkdir
|
||||||
|
}
|
||||||
|
targetDir = path.Join(wd, targetPath)
|
||||||
if !isDir {
|
if !isDir {
|
||||||
targetDir = path.Dir(targetDir)
|
targetDir = path.Dir(targetDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
files, err := activeUser.CacheFilesDirectoriesList(targetDir)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
if file == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
appendLine string
|
||||||
|
)
|
||||||
|
|
||||||
|
// 已经有的情况
|
||||||
|
if !closed {
|
||||||
|
if !strings.HasPrefix(file.Path, path.Clean(path.Join(targetDir, path.Base(targetPath)))) {
|
||||||
|
if path.Base(targetDir) == path.Base(targetPath) {
|
||||||
|
appendLine = strings.Join(append(lineArgs[:numArgs-1], escaper.EscapeByRuneFunc(path.Join(targetPath, file.FileName), cmdRuneFunc)), " ")
|
||||||
|
goto handle
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
appendLine = strings.Join(append(lineArgs[:numArgs-1], escaper.EscapeByRuneFunc(path.Clean(path.Join(path.Dir(targetPath), file.FileName)), cmdRuneFunc)), " ")
|
||||||
|
goto handle
|
||||||
|
}
|
||||||
|
// 没有的情况
|
||||||
|
appendLine = strings.Join(append(lineArgs, escaper.EscapeByRuneFunc(file.FileName, cmdRuneFunc)), " ")
|
||||||
|
goto handle
|
||||||
|
|
||||||
|
handle:
|
||||||
|
if file.IsFolder() {
|
||||||
|
s = append(s, appendLine+"/")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
s = append(s, appendLine+" ")
|
||||||
|
continue
|
||||||
|
}
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -487,6 +529,10 @@ func main() {
|
|||||||
// Action: func(c *cli.Context) error {
|
// Action: func(c *cli.Context) error {
|
||||||
// os.Setenv(config.EnvVerbose, c.String("verbose"))
|
// os.Setenv(config.EnvVerbose, c.String("verbose"))
|
||||||
// fmt.Println("显示调试日志", logger.IsVerbose)
|
// fmt.Println("显示调试日志", logger.IsVerbose)
|
||||||
|
//
|
||||||
|
// user := config.Config.ActiveUser()
|
||||||
|
// fdl,_ := user.CacheFilesDirectoriesList("/tmp")
|
||||||
|
// fmt.Println(fdl)
|
||||||
// return nil
|
// return nil
|
||||||
// },
|
// },
|
||||||
// Flags: []cli.Flag{
|
// Flags: []cli.Flag{
|
||||||
|
Loading…
Reference in New Issue
Block a user