use openapi as default api for commands

This commit is contained in:
tickstep 2024-03-02 17:38:21 +08:00
parent 2fe5cc5414
commit 3c0da7fc1d
18 changed files with 94 additions and 353 deletions

View File

@ -15,7 +15,6 @@ package command
import (
"fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/internal/config"
"github.com/urfave/cli"
@ -96,24 +95,32 @@ func RunChangeDirectory(driveId, targetPath string) {
user := config.Config.ActiveUser()
targetPath = user.PathJoin(driveId, targetPath)
//targetPathInfo, err := user.PanClient().WebapiPanClient().FileInfoByPath(driveId, targetPath)
files, err := matchPathByShellPattern(driveId, targetPath)
// 获取目标路径文件信息
targetPathInfo, err := user.PanClient().OpenapiPanClient().FileInfoByPath(driveId, targetPath)
if err != nil {
fmt.Println(err)
return
}
var targetPathInfo *aliyunpan.FileEntity
if len(files) == 1 {
targetPathInfo = files[0]
} else {
for _, f := range files {
if f.IsFolder() {
targetPathInfo = f
break
}
}
}
// 适配通配符路径获取目标文件信息(弃用,容易触发风控)
//files, err := matchPathByShellPattern(driveId, targetPath)
//if err != nil {
// fmt.Println(err)
// return
//}
//
//var targetPathInfo *aliyunpan.FileEntity
//if len(files) == 1 {
// targetPathInfo = files[0]
//} else {
// for _, f := range files {
// if f.IsFolder() {
// targetPathInfo = f
// break
// }
// }
//}
if targetPathInfo == nil {
fmt.Println("路径不存在")
return

View File

@ -18,16 +18,10 @@ import (
"fmt"
"github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/cmder/cmdutil"
"github.com/tickstep/aliyunpan/internal/config"
"github.com/tickstep/aliyunpan/library/crypto"
"github.com/tickstep/library-go/getip"
"github.com/urfave/cli"
"net/url"
"path"
"strconv"
"strings"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan/internal/config"
)
type (
@ -74,85 +68,6 @@ func parseDriveId(c *cli.Context) string {
return driveId
}
// newRapidUploadItem 通过解析秒传链接创建秒传实体
func newRapidUploadItem(rapidUploadShareLink string) (*RapidUploadItem, error) {
if strings.IndexAny(rapidUploadShareLink, "aliyunpan://") != 0 {
return nil, fmt.Errorf("秒传链接格式错误: %s", rapidUploadShareLink)
}
// 格式aliyunpan://文件名|sha1|文件大小|<相对路径>
rapidUploadShareLinkStr := strings.Replace(rapidUploadShareLink, "aliyunpan://", "", 1)
item := &RapidUploadItem{}
parts := strings.Split(rapidUploadShareLinkStr, "|")
if len(parts) < 4 {
return nil, fmt.Errorf("秒传链接格式错误: %s", rapidUploadShareLink)
}
// hash
if len(parts[1]) == 0 {
return nil, fmt.Errorf("文件sha1错误: %s", rapidUploadShareLink)
}
item.FileSha1 = strings.TrimSpace(parts[1])
// size
if size, e := strconv.ParseInt(parts[2], 10, 64); e == nil {
item.FileSize = size
} else {
return nil, fmt.Errorf("文件大小错误: %s", rapidUploadShareLink)
}
// path
relativePath, _ := url.QueryUnescape(parts[3])
item.FilePath = path.Join(relativePath, parts[0])
// result
return item, nil
}
func newRapidUploadItemFromFileEntity(fileEntity *aliyunpan.FileEntity) *RapidUploadItem {
if fileEntity == nil {
return nil
}
return &RapidUploadItem{
FileSha1: fileEntity.ContentHash,
FileSize: fileEntity.FileSize,
FilePath: fileEntity.Path,
}
}
// 创建秒传链接
// 链接格式说明aliyunpan://文件名|sha1|文件大小|<相对路径>
// "相对路径" 可以为空,为空代表存储到网盘根目录
func (r *RapidUploadItem) createRapidUploadLink(hideRelativePath bool) string {
fullLink := &strings.Builder{}
p := r.FilePath
p = strings.ReplaceAll(p, "\\", "/")
fileName := path.Base(p)
dirPath := path.Dir(p)
// 去掉开头/
if strings.Index(dirPath, "/") == 0 {
dirPath = dirPath[1:]
}
// 相对路径编码
dirPath = url.QueryEscape(dirPath)
// 隐藏相对路径
if hideRelativePath {
dirPath = ""
}
// 拼接
fmt.Fprintf(fullLink, "aliyunpan://%s|%s|%d|%s",
fileName, strings.ToUpper(r.FileSha1), r.FileSize, dirPath)
return fullLink.String()
}
func CmdConfig() cli.Command {
return cli.Command{
Name: "config",

View File

@ -1,21 +1,13 @@
package command
import (
"fmt"
"testing"
)
func TestRapidUploadItem_createRapidUploadLink(t *testing.T) {
item := &RapidUploadItem{
FileSha1: "752FCCBFB2436A6FFCA3B287831D4FAA5654B07E",
FileSize: 7005440,
FilePath: "/dgsdg/rtt5/我的文件夹/file我的文件.dmg",
}
fmt.Println(item.createRapidUploadLink(false))
}
func TestRapidUploadItem_newRapidUploadItem(t *testing.T) {
link := "aliyunpan://file我的文件.dmg|752FCCBFB2436A6FFCA3B287831D4FAA5654B07E|7005440|dgsdg%2Frtt5%2F%E6%88%91%E7%9A%84%E6%96%87%E4%BB%B6%E5%A4%B9"
item,_ := newRapidUploadItem(link)
fmt.Println(item)
}
}

View File

@ -141,22 +141,31 @@ func RunLs(driveId, targetPath string, lsOptions *LsOptions,
activeUser := config.Config.ActiveUser()
targetPath = activeUser.PathJoin(driveId, targetPath)
files, err := matchPathByShellPattern(driveId, targetPath)
// 获取目标路径文件信息
targetPathInfo, err := activeUser.PanClient().OpenapiPanClient().FileInfoByPath(driveId, targetPath)
if err != nil {
fmt.Println(err)
return
}
var targetPathInfo *aliyunpan.FileEntity
if len(files) == 1 {
targetPathInfo = files[0]
} else {
for _, f := range files {
if f.IsFolder() {
targetPathInfo = f
break
}
}
}
// 适配通配符路径获取目标文件信息(弃用,容易触发风控)
//files, err := matchPathByShellPattern(driveId, targetPath)
//if err != nil {
// fmt.Println(err)
// return
//}
//var targetPathInfo *aliyunpan.FileEntity
//if len(files) == 1 {
// targetPathInfo = files[0]
//} else {
// for _, f := range files {
// if f.IsFolder() {
// targetPathInfo = f
// break
// }
// }
//}
if targetPathInfo == nil {
fmt.Println("目录路径不存在")
return
@ -169,7 +178,7 @@ func RunLs(driveId, targetPath string, lsOptions *LsOptions,
fileListParam.OrderBy = orderBy
fileListParam.OrderDirection = orderDirection
if targetPathInfo.IsFolder() {
fileResult, err1 := activeUser.PanClient().WebapiPanClient().FileListGetAll(fileListParam, 200)
fileResult, err1 := activeUser.PanClient().OpenapiPanClient().FileListGetAll(fileListParam, 200)
if err1 != nil {
fmt.Println(err1)
return

View File

@ -56,7 +56,7 @@ func RunMkdir(driveId, name string) {
fullpath := activeUser.PathJoin(driveId, name)
rs := &aliyunpan.MkdirResult{}
err := apierror.NewFailedApiError("")
rs, err = activeUser.PanClient().WebapiPanClient().Mkdir(driveId, "", fullpath)
rs, err = activeUser.PanClient().OpenapiPanClient().MkdirByFullPath(driveId, fullpath)
if err != nil {
fmt.Println("创建文件夹失败:" + err.Error())

View File

@ -98,7 +98,7 @@ func RunMove(driveId string, paths ...string) {
})
cacheCleanPaths = append(cacheCleanPaths, path.Dir(mfi.Path))
}
fmr, er := activeUser.PanClient().WebapiPanClient().FileMove(moveFileParamList)
fmr, er := activeUser.PanClient().OpenapiPanClient().FileMove(moveFileParamList)
for _, rs := range fmr {
if !rs.Success {
@ -138,7 +138,7 @@ func getFileInfo(driveId string, paths ...string) (opFileList []*aliyunpan.FileE
// the last one is the target file path
targetFilePath := path.Clean(paths[len(paths)-1])
absolutePath := activeUser.PathJoin(driveId, targetFilePath)
targetFile, err := activeUser.PanClient().WebapiPanClient().FileInfoByPath(driveId, absolutePath)
targetFile, err := activeUser.PanClient().OpenapiPanClient().FileInfoByPath(driveId, absolutePath)
if err != nil || !targetFile.IsFolder() {
return nil, nil, nil, fmt.Errorf("指定目标文件夹不存在")
}

View File

@ -52,7 +52,7 @@ func CmdQuota() cli.Command {
}
func RunGetQuotaInfo() (quotaInfo *QuotaInfo, error error) {
user, err := GetActivePanClient().WebapiPanClient().GetUserInfo()
user, err := GetActivePanClient().OpenapiPanClient().GetUserInfo()
if err != nil {
return nil, err
}

View File

@ -136,14 +136,14 @@ func RunRename(driveId string, oldName string, newName string) {
}
fileId := ""
r, err := GetActivePanClient().WebapiPanClient().FileInfoByPath(driveId, activeUser.PathJoin(driveId, oldName))
r, err := GetActivePanClient().OpenapiPanClient().FileInfoByPath(driveId, activeUser.PathJoin(driveId, oldName))
if err != nil {
fmt.Printf("原文件不存在: %s, %s\n", oldName, err)
return
}
fileId = r.FileId
b, e := activeUser.PanClient().WebapiPanClient().FileRename(driveId, fileId, path.Base(newName))
b, e := activeUser.PanClient().OpenapiPanClient().FileRename(driveId, fileId, path.Base(newName))
if e != nil {
fmt.Println(e.Err)
return
@ -234,7 +234,7 @@ func RunRenameBatch(skipConfirm bool, driveId string, expression, replacement, f
// 重命名
for _, file := range files {
b, e := activeUser.PanClient().WebapiPanClient().FileRename(driveId, file.file.FileId, file.newFileName)
b, e := activeUser.PanClient().OpenapiPanClient().FileRename(driveId, file.file.FileId, file.newFileName)
if e != nil {
fmt.Println(e.Err)
return

View File

@ -106,7 +106,7 @@ func RunRemove(driveId string, paths ...string) {
// delete
successDelFileEntity := []*aliyunpan.FileEntity{}
fdr, err := activeUser.PanClient().WebapiPanClient().FileDelete(delFileInfos)
fdr, err := activeUser.PanClient().OpenapiPanClient().FileDelete(delFileInfos)
if fdr != nil {
for _, item := range fdr {
if !item.Success {

View File

@ -21,7 +21,6 @@ import (
"github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/cmder/cmdtable"
"github.com/tickstep/aliyunpan/internal/config"
"github.com/tickstep/library-go/logger"
"github.com/urfave/cli"
"os"
"path"
@ -458,36 +457,3 @@ func ExportCsv(savePath string, data [][]string) bool {
w.Flush()
return true
}
// 创建秒传链接
func RunShareMc(driveId string, hideRelativePath bool, panPaths []string) {
activeUser := config.Config.ActiveUser()
panClient := activeUser.PanClient()
totalCount := 0
for _, panPath := range panPaths {
panPath = activeUser.PathJoin(driveId, panPath)
panClient.WebapiPanClient().FilesDirectoriesRecurseList(driveId, panPath, func(depth int, _ string, fd *aliyunpan.FileEntity, apiError *apierror.ApiError) bool {
if apiError != nil {
logger.Verbosef("%s\n", apiError)
return true
}
// 只需要文件即可
if !fd.IsFolder() {
item := newRapidUploadItemFromFileEntity(fd)
jstr := item.createRapidUploadLink(hideRelativePath)
if len(jstr) <= 0 {
logger.Verboseln("create rapid upload link err")
return false
}
// print
fmt.Println(jstr)
totalCount += 1
time.Sleep(time.Duration(100) * time.Millisecond)
}
return true
})
}
fmt.Printf("\n秒传链接总数量: %d\n", totalCount)
}

View File

@ -113,23 +113,31 @@ func getTree(driveId, pathStr string, depth int, statistic *treeStatistic, setti
pathStr = activeUser.PathJoin(driveId, pathStr)
pathStr = path.Clean(pathStr)
files, err := matchPathByShellPattern(driveId, pathStr)
// 获取目标路径文件信息
targetPathInfo, err := activeUser.PanClient().OpenapiPanClient().FileInfoByPath(driveId, pathStr)
if err != nil {
fmt.Println(err)
return
}
var targetPathInfo *aliyunpan.FileEntity
if len(files) == 1 {
targetPathInfo = files[0]
} else {
for _, f := range files {
if f.IsFolder() {
targetPathInfo = f
break
}
}
}
// 适配通配符路径获取目标文件信息(弃用,容易触发风控)
//files, err := matchPathByShellPattern(driveId, pathStr)
//if err != nil {
// fmt.Println(err)
// return
//}
//var targetPathInfo *aliyunpan.FileEntity
//if len(files) == 1 {
// targetPathInfo = files[0]
//} else {
// for _, f := range files {
// if f.IsFolder() {
// targetPathInfo = f
// break
// }
// }
//}
if targetPathInfo == nil {
fmt.Println("路径不存在")
return
@ -146,7 +154,7 @@ func getTree(driveId, pathStr string, depth int, statistic *treeStatistic, setti
fileListParam.OrderBy = aliyunpan.FileOrderByName
fileListParam.OrderDirection = aliyunpan.FileOrderDirectionAsc
if targetPathInfo.IsFolder() {
fileResult, err := activeUser.PanClient().WebapiPanClient().FileListGetAll(fileListParam, 500)
fileResult, err := activeUser.PanClient().OpenapiPanClient().FileListGetAll(fileListParam, 500)
if err != nil {
fmt.Println(err)
return
@ -169,7 +177,7 @@ func getTree(driveId, pathStr string, depth int, statistic *treeStatistic, setti
} else {
fmt.Printf("%v%v %v/\n", indentPrefixStr, pathPrefix, file.FileName)
}
getTree(driveId, targetPathInfo.Path+"/"+file.Path, depth+1, statistic, setting)
getTree(driveId, targetPathInfo.Path+"/"+file.FileName, depth+1, statistic, setting)
continue
}
@ -214,9 +222,9 @@ func getTree(driveId, pathStr string, depth int, statistic *treeStatistic, setti
// RunTree 列出树形图
func RunTree(driveId, pathStr string, showFullPath, showFileSize bool, minSize, maxSize int64) {
activeUser := config.Config.ActiveUser()
activeUser.PanClient().WebapiPanClient().ClearCache()
activeUser.PanClient().WebapiPanClient().EnableCache()
defer activeUser.PanClient().WebapiPanClient().DisableCache()
activeUser.PanClient().OpenapiPanClient().ClearCache()
activeUser.PanClient().OpenapiPanClient().EnableCache()
defer activeUser.PanClient().OpenapiPanClient().DisableCache()
pathStr = activeUser.PathJoin(driveId, pathStr)
statistic := &treeStatistic{
CountOfDir: 0,

View File

@ -217,59 +217,6 @@ func CmdUpload() cli.Command {
}
}
func CmdRapidUpload() cli.Command {
return cli.Command{
Name: "rapidupload",
Aliases: []string{"ru"},
Usage: "手动秒传文件",
UsageText: cmder.App().Name + " rapidupload \"aliyunpan://file.dmg|752FCCBFB2436A6FFCA3B287831D4FAA5654B07E|7005440|pan_folder\"",
Description: `
使用此功能秒传文件, 前提是知道文件的大小, sha1, 且网盘中存在一模一样的文件.
上传的文件将会保存到网盘的目标目录文件的秒传链接可以通过share或者export命令获取
链接格式说明aliyunpan://文件名|sha1|文件大小|<相对路径>
"相对路径" 可以为空为空代表存储到网盘根目录
示例:
1. 如果秒传成功, 则保存到网盘路径 /pan_folder/file.dmg
aliyunpan rapidupload "aliyunpan://file.dmg|752FCCBFB2436A6FFCA3B287831D4FAA5654B07E|7005440|pan_folder"
2. 如果秒传成功, 则保存到网盘路径 /file.dmg
aliyunpan rapidupload "aliyunpan://file.dmg|752FCCBFB2436A6FFCA3B287831D4FAA5654B07E|7005440|"
3. 同时秒传多个文件如果秒传成功, 则保存到网盘路径 /pan_folder/file.dmg, /pan_folder/file1.dmg
aliyunpan rapidupload "aliyunpan://file.dmg|752FCCBFB2436A6FFCA3B287831D4FAA5654B07E|7005440|pan_folder" "aliyunpan://file1.dmg|752FCCBFB2436A6FFCA3B287831D4FAA5654B07E|7005440|pan_folder"
`,
Category: "阿里云盘",
Before: ReloadConfigFunc,
Action: func(c *cli.Context) error {
if c.NArg() <= 0 {
cli.ShowCommandHelp(c, c.Command.Name)
return nil
}
subArgs := c.Args()
RunRapidUpload(parseDriveId(c), c.Bool("ow"), subArgs, c.String("path"))
return nil
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "ow",
Usage: "overwrite, 覆盖已存在的文件。已存在的文件会并移到回收站",
},
cli.StringFlag{
Name: "path",
Usage: "存储到网盘目录,绝对路径,例如:/myfolder",
Value: "",
},
cli.StringFlag{
Name: "driveId",
Usage: "网盘ID",
Value: "",
},
},
}
}
// RunUpload 执行文件上传
func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
activeUser := GetActiveUser()
@ -511,108 +458,3 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
}
activeUser.DeleteCache(GetAllPathFolderByPath(savePath))
}
// RunRapidUpload 秒传
func RunRapidUpload(driveId string, isOverwrite bool, fileMetaList []string, savePanPath string) {
activeUser := GetActiveUser()
savePanPath = activeUser.PathJoin(driveId, savePanPath)
if len(fileMetaList) == 0 {
fmt.Println("秒传链接为空")
return
}
items := []*RapidUploadItem{}
// parse file meta strings
for _, fileMeta := range fileMetaList {
item, e := newRapidUploadItem(fileMeta)
if e != nil {
fmt.Println(e)
continue
}
if item == nil {
fmt.Println("秒传链接格式错误: ", fileMeta)
continue
}
// pan path
item.FilePath = path.Join(savePanPath, item.FilePath)
// append
items = append(items, item)
}
// upload one by one
for _, item := range items {
fmt.Println("准备秒传:", item.FilePath)
if ee := doRapidUpload(driveId, isOverwrite, item); ee != nil {
fmt.Println(ee)
} else {
fmt.Printf("秒传成功, 保存到网盘路径:%s\n", item.FilePath)
}
}
}
func doRapidUpload(driveId string, isOverwrite bool, item *RapidUploadItem) error {
activeUser := GetActiveUser()
panClient := activeUser.PanClient()
var apierr *apierror.ApiError
var rs *aliyunpan.MkdirResult
var appCreateUploadFileParam *aliyunpan.CreateFileUploadParam
var saveFilePath string
panDir, panFileName := path.Split(item.FilePath)
saveFilePath = item.FilePath
if panDir != "/" {
rs, apierr = panClient.WebapiPanClient().MkdirRecursive(driveId, "", "", 0, strings.Split(path.Clean(panDir), "/"))
if apierr != nil || rs.FileId == "" {
return fmt.Errorf("创建云盘文件夹失败")
}
} else {
rs = &aliyunpan.MkdirResult{}
rs.FileId = aliyunpan.DefaultRootParentFileId
}
time.Sleep(time.Duration(2) * time.Second)
if isOverwrite {
// 标记覆盖旧同名文件
// 检查同名文件是否存在
efi, apierr := panClient.WebapiPanClient().FileInfoByPath(driveId, saveFilePath)
if apierr != nil && apierr.Code != apierror.ApiCodeFileNotFoundCode {
return fmt.Errorf("检测同名文件失败,请稍后重试")
}
if efi != nil && efi.FileId != "" {
// existed, delete it
fileDeleteResult, err1 := panClient.WebapiPanClient().FileDelete([]*aliyunpan.FileBatchActionParam{{DriveId: efi.DriveId, FileId: efi.FileId}})
if err1 != nil || len(fileDeleteResult) == 0 {
return fmt.Errorf("无法删除文件,请稍后重试")
}
time.Sleep(time.Duration(500) * time.Millisecond)
if fileDeleteResult[0].Success {
logger.Verboseln("检测到同名文件,已移动到回收站: ", saveFilePath)
} else {
return fmt.Errorf("无法删除文件,请稍后重试")
}
}
}
appCreateUploadFileParam = &aliyunpan.CreateFileUploadParam{
DriveId: driveId,
Name: panFileName,
Size: item.FileSize,
ContentHash: item.FileSha1,
ParentFileId: rs.FileId,
}
uploadOpEntity, apierr := panClient.WebapiPanClient().CreateUploadFile(appCreateUploadFileParam)
if apierr != nil {
return fmt.Errorf("创建秒传任务失败:" + apierr.Error())
}
if uploadOpEntity.RapidUpload {
logger.Verboseln("秒传成功, 保存到网盘路径: ", path.Join(panDir, uploadOpEntity.FileName))
} else {
return fmt.Errorf("失败,文件未曾上传,无法秒传")
}
return nil
}

View File

@ -129,7 +129,7 @@ func CmdWho() cli.Command {
}
activeUser := config.Config.ActiveUser()
cloudName := activeUser.GetDriveById(activeUser.ActiveDriveId).DriveName
fmt.Printf("当前帐号UID: %s, 昵称: %s, 用户名: %s, 网盘:%s\n", activeUser.UserId, activeUser.Nickname, activeUser.AccountName, cloudName)
fmt.Printf("当前帐号UID: %s, 昵称: %s, 用户名: %s, 当前使用网盘:%s\n", activeUser.UserId, activeUser.Nickname, activeUser.AccountName, cloudName)
return nil
},
}

View File

@ -58,7 +58,7 @@ var (
// RunTestShellPattern 执行测试通配符
func RunTestShellPattern(driveId string, pattern string) {
acUser := GetActiveUser()
files, err := acUser.PanClient().WebapiPanClient().MatchPathByShellPattern(driveId, GetActiveUser().PathJoin(driveId, pattern))
files, err := acUser.PanClient().OpenapiPanClient().MatchPathByShellPattern(driveId, GetActiveUser().PathJoin(driveId, pattern))
if err != nil {
fmt.Println(err)
return
@ -73,7 +73,7 @@ func RunTestShellPattern(driveId string, pattern string) {
func matchPathByShellPattern(driveId string, patterns ...string) (files []*aliyunpan.FileEntity, e error) {
acUser := GetActiveUser()
for k := range patterns {
ps, err := acUser.PanClient().WebapiPanClient().MatchPathByShellPattern(driveId, acUser.PathJoin(driveId, patterns[k]))
ps, err := acUser.PanClient().OpenapiPanClient().MatchPathByShellPattern(driveId, acUser.PathJoin(driveId, patterns[k]))
if err != nil {
return nil, err
}
@ -140,7 +140,7 @@ func NewWebLoginToken(accessToken string, expired int64) aliyunpan.WebLoginToken
}
}
// RefreshTokenInNeed 刷新webapi access token
// RefreshTokenInNeed 刷新 webapi access token
func RefreshTokenInNeed(activeUser *config.PanUser, deviceName string) bool {
if activeUser == nil {
return false

View File

@ -30,7 +30,7 @@ func (pu *PanUser) DeleteOneCache(dirPath string) {
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.WebapiPanClient().FileInfoByPath(pu.ActiveDriveId, pathStr)
fi, apiError = pu.panClient.OpenapiPanClient().FileInfoByPath(pu.ActiveDriveId, pathStr)
if apiError != nil {
return nil
}
@ -38,7 +38,7 @@ func (pu *PanUser) CacheFilesDirectoriesList(pathStr string) (fdl aliyunpan.File
DriveId: pu.ActiveDriveId,
ParentFileId: fi.FileId,
}
fdl, apiError = pu.panClient.WebapiPanClient().FileListGetAll(fileListParam, 100)
fdl, apiError = pu.panClient.OpenapiPanClient().FileListGetAll(fileListParam, 200)
if apiError != nil {
return nil
}

View File

@ -410,7 +410,7 @@ func (c *PanConfig) ActiveUser() *PanUser {
u.DriveList = user.DriveList
// check workdir valid or not
if user.IsFileDriveActive() {
fe, err1 := u.PanClient().WebapiPanClient().FileInfoByPath(u.ActiveDriveId, u.Workdir)
fe, err1 := u.PanClient().OpenapiPanClient().FileInfoByPath(u.ActiveDriveId, u.Workdir)
if err1 != nil {
// default to root
u.Workdir = "/"
@ -419,7 +419,7 @@ func (c *PanConfig) ActiveUser() *PanUser {
u.WorkdirFileEntity = *fe
}
} else if user.IsResourceDriveActive() {
fe, err1 := u.PanClient().WebapiPanClient().FileInfoByPath(u.ActiveDriveId, u.ResourceWorkdir)
fe, err1 := u.PanClient().OpenapiPanClient().FileInfoByPath(u.ActiveDriveId, u.ResourceWorkdir)
if err1 != nil {
// default to root
u.ResourceWorkdir = "/"

View File

@ -181,7 +181,7 @@ doWebLoginAct:
// web api token maybe expired
// check & refresh new one
webUserInfo, err2 := webPanClient.GetUserInfo()
if err != nil {
if err2 != nil {
if err2.Code == apierror.ApiCodeTokenExpiredCode && tryRefreshWebToken {
tryRefreshWebToken = false
wt, e := loginHelper.GetWebapiNewToken(ticketId, userId)
@ -196,7 +196,7 @@ doWebLoginAct:
goto doWebLoginAct
}
}
return nil, err
return nil, err2
}
// web create session
@ -284,14 +284,14 @@ func (pu *PanUser) PathJoin(driveId, p string) string {
func (pu *PanUser) FreshWorkdirInfo() {
if pu.IsFileDriveActive() {
fe, err := pu.PanClient().WebapiPanClient().FileInfoById(pu.ActiveDriveId, pu.WorkdirFileEntity.FileId)
fe, err := pu.PanClient().OpenapiPanClient().FileInfoById(pu.ActiveDriveId, pu.WorkdirFileEntity.FileId)
if err != nil {
logger.Verboseln("刷新工作目录信息失败")
return
}
pu.WorkdirFileEntity = *fe
} else if pu.IsAlbumDriveActive() {
fe, err := pu.PanClient().WebapiPanClient().FileInfoById(pu.ActiveDriveId, pu.AlbumWorkdirFileEntity.FileId)
fe, err := pu.PanClient().OpenapiPanClient().FileInfoById(pu.ActiveDriveId, pu.AlbumWorkdirFileEntity.FileId)
if err != nil {
logger.Verboseln("刷新工作目录信息失败")
return

View File

@ -263,6 +263,8 @@ func main() {
targetDir = path.Dir(targetDir)
}
}
// tab键补全路径
files, err := activeUser.CacheFilesDirectoriesList(targetDir)
if err != nil {
return