From 55e989d8219871df043eebdee05b39852fbf84eb Mon Sep 17 00:00:00 2001 From: xiaoyaofenfen <1254525673@qq.com> Date: Sat, 7 Oct 2023 16:42:43 +0800 Subject: [PATCH] adapt resource drive --- internal/command/cd.go | 7 ++++++- internal/command/drive_list.go | 7 ++++++- internal/config/pan_config.go | 11 ++++++++++- internal/config/pan_user.go | 31 +++++++++++++++++++++++++++++-- main.go | 9 +++++++-- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/internal/command/cd.go b/internal/command/cd.go index f213856..6c8ff1d 100644 --- a/internal/command/cd.go +++ b/internal/command/cd.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -82,6 +82,8 @@ func CmdPwd() cli.Command { activeUser := config.Config.ActiveUser() if activeUser.IsFileDriveActive() { fmt.Println(activeUser.Workdir) + } else if activeUser.IsResourceDriveActive() { + fmt.Println(activeUser.ResourceWorkdir) } else if activeUser.IsAlbumDriveActive() { fmt.Println(activeUser.AlbumWorkdir) } @@ -125,6 +127,9 @@ func RunChangeDirectory(driveId, targetPath string) { if user.IsFileDriveActive() { user.Workdir = targetPathInfo.Path user.WorkdirFileEntity = *targetPathInfo + } else if user.IsResourceDriveActive() { + user.ResourceWorkdir = targetPathInfo.Path + user.ResourceWorkdirFileEntity = *targetPathInfo } else if user.IsAlbumDriveActive() { user.AlbumWorkdir = targetPathInfo.Path user.AlbumWorkdirFileEntity = *targetPathInfo diff --git a/internal/command/drive_list.go b/internal/command/drive_list.go index 2a5b56b..24365e0 100644 --- a/internal/command/drive_list.go +++ b/internal/command/drive_list.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -100,6 +100,11 @@ func RunSwitchDriveList(targetDriveId string) { config.Config.ActiveUser().Workdir = "/" config.Config.ActiveUser().WorkdirFileEntity = *aliyunpan.NewFileEntityForRootDir() } + } else if activeUser.IsResourceDriveActive() { + if activeUser.ResourceWorkdir == "" { + config.Config.ActiveUser().ResourceWorkdir = "/" + config.Config.ActiveUser().ResourceWorkdirFileEntity = *aliyunpan.NewFileEntityForRootDir() + } } else if activeUser.IsAlbumDriveActive() { if activeUser.AlbumWorkdir == "" { config.Config.ActiveUser().AlbumWorkdir = "/" diff --git a/internal/config/pan_config.go b/internal/config/pan_config.go index 94e88e6..b0b06f0 100644 --- a/internal/config/pan_config.go +++ b/internal/config/pan_config.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -398,6 +398,15 @@ func (c *PanConfig) ActiveUser() *PanUser { } else { u.WorkdirFileEntity = *fe } + } else if user.IsResourceDriveActive() { + fe, err1 := u.PanClient().FileInfoByPath(u.ActiveDriveId, u.ResourceWorkdir) + if err1 != nil { + // default to root + u.ResourceWorkdir = "/" + u.ResourceWorkdirFileEntity = *aliyunpan.NewFileEntityForRootDir() + } else { + u.ResourceWorkdirFileEntity = *fe + } } else if user.IsAlbumDriveActive() { fe, err1 := u.PanClient().FileInfoByPath(u.ActiveDriveId, u.AlbumWorkdir) if err1 != nil { diff --git a/internal/config/pan_user.go b/internal/config/pan_user.go index 33f7e0d..7d50e8c 100644 --- a/internal/config/pan_user.go +++ b/internal/config/pan_user.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -48,14 +48,29 @@ func (d DriveInfoList) GetAlbumDriveId() string { return "" } +func (d DriveInfoList) GetResourceDriveId() string { + for _, drive := range d { + if drive.DriveTag == "Resource" { + return drive.DriveId + } + } + return "" +} + type PanUser struct { UserId string `json:"userId"` Nickname string `json:"nickname"` AccountName string `json:"accountName"` + // 文件/备份盘 Workdir string `json:"workdir"` WorkdirFileEntity aliyunpan.FileEntity `json:"workdirFileEntity"` + // 资源库 + ResourceWorkdir string `json:"resourceWorkdir"` + ResourceWorkdirFileEntity aliyunpan.FileEntity `json:"resourceWorkdirFileEntity"` + + // 相册 AlbumWorkdir string `json:"albumWorkdir"` AlbumWorkdirFileEntity aliyunpan.FileEntity `json:"albumWorkdirFileEntity"` @@ -129,7 +144,8 @@ doLoginAct: // drive list u.DriveList = DriveInfoList{ - {DriveId: userInfo.FileDriveId, DriveTag: "File", DriveName: "文件"}, + {DriveId: userInfo.FileDriveId, DriveTag: "File", DriveName: "备份盘"}, + {DriveId: userInfo.ResourceDriveId, DriveTag: "Resource", DriveName: "资源库"}, {DriveId: userInfo.AlbumDriveId, DriveTag: "Album", DriveName: "相册"}, } } else { @@ -165,6 +181,8 @@ func (pu *PanUser) PathJoin(driveId, p string) string { if di != nil { if di.IsFileDrive() { wd = pu.Workdir + } else if di.IsResourceDrive() { + wd = pu.ResourceWorkdir } else if di.IsAlbumDrive() { wd = pu.AlbumWorkdir } @@ -239,6 +257,11 @@ func (pu *PanUser) IsAlbumDriveActive() bool { return d != nil && d.IsAlbumDrive() } +func (pu *PanUser) IsResourceDriveActive() bool { + d := pu.GetActiveDriveInfo() + return d != nil && d.IsResourceDrive() +} + func (di *DriveInfo) IsFileDrive() bool { return di.DriveTag == "File" } @@ -246,3 +269,7 @@ func (di *DriveInfo) IsFileDrive() bool { func (di *DriveInfo) IsAlbumDrive() bool { return di.DriveTag == "Album" } + +func (di *DriveInfo) IsResourceDrive() bool { + return di.DriveTag == "Resource" +} diff --git a/main.go b/main.go index e56cc3a..2cc0ff2 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -253,6 +253,8 @@ func main() { wd := "/" if activeUser.IsFileDriveActive() { wd = activeUser.Workdir + } else if activeUser.IsResourceDriveActive() { + wd = activeUser.ResourceWorkdir } else if activeUser.IsAlbumDriveActive() { wd = activeUser.AlbumWorkdir } @@ -347,7 +349,10 @@ func main() { wd := "/" if activeUser.IsFileDriveActive() { wd = activeUser.Workdir - prompt = app.Name + ":" + converter.ShortDisplay(path.Base(wd), NameShortDisplayNum) + " " + activeUser.Nickname + "$ " + prompt = app.Name + ":" + converter.ShortDisplay(path.Base(wd), NameShortDisplayNum) + " " + activeUser.Nickname + "(备份盘)$ " + } else if activeUser.IsResourceDriveActive() { + wd = activeUser.ResourceWorkdir + prompt = app.Name + ":" + converter.ShortDisplay(path.Base(wd), NameShortDisplayNum) + " " + activeUser.Nickname + "(资源库)$ " } else if activeUser.IsAlbumDriveActive() { wd = activeUser.AlbumWorkdir prompt = app.Name + ":" + converter.ShortDisplay(path.Base(wd), NameShortDisplayNum) + " " + activeUser.Nickname + "(相册)$ "