adapt webapi new struct

This commit is contained in:
tickstep 2024-03-03 14:02:05 +08:00
parent 4c0c8a4ff9
commit b79cd7bafb
8 changed files with 39 additions and 33 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/olekukonko/tablewriter"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/cmder/cmdtable"
"github.com/tickstep/aliyunpan/internal/config"
@ -335,7 +336,7 @@ func CmdAlbum() cli.Command {
func RunAlbumList() {
activeUser := GetActiveUser()
records, err := activeUser.PanClient().WebapiPanClient().AlbumListGetAll(&aliyunpan.AlbumListParam{})
records, err := activeUser.PanClient().WebapiPanClient().AlbumListGetAll(&aliyunpan_web.AlbumListParam{})
if err != nil {
fmt.Printf("获取相簿列表失败: %s\n", err)
return
@ -358,7 +359,7 @@ func RunAlbumCreate(name, description string) {
}
activeUser := GetActiveUser()
_, err := activeUser.PanClient().WebapiPanClient().AlbumCreate(&aliyunpan.AlbumCreateParam{
_, err := activeUser.PanClient().WebapiPanClient().AlbumCreate(&aliyunpan_web.AlbumCreateParam{
Name: name,
Description: description,
})
@ -376,7 +377,7 @@ func RunAlbumDelete(nameList []string) {
}
activeUser := GetActiveUser()
records, err := activeUser.PanClient().WebapiPanClient().AlbumListGetAll(&aliyunpan.AlbumListParam{})
records, err := activeUser.PanClient().WebapiPanClient().AlbumListGetAll(&aliyunpan_web.AlbumListParam{})
if err != nil {
fmt.Printf("获取相簿列表失败: %s\n", err)
return
@ -386,7 +387,7 @@ func RunAlbumDelete(nameList []string) {
for i, name := range nameList {
if name == record.Name {
nameList = append(nameList[:i], nameList[i+1:]...)
_, err := activeUser.PanClient().WebapiPanClient().AlbumDelete(&aliyunpan.AlbumDeleteParam{
_, err := activeUser.PanClient().WebapiPanClient().AlbumDelete(&aliyunpan_web.AlbumDeleteParam{
AlbumId: record.AlbumId,
})
if err != nil {
@ -401,8 +402,8 @@ func RunAlbumDelete(nameList []string) {
}
}
func getAlbumFromName(activeUser *config.PanUser, name string) *aliyunpan.AlbumEntity {
records, err := activeUser.PanClient().WebapiPanClient().AlbumListGetAll(&aliyunpan.AlbumListParam{})
func getAlbumFromName(activeUser *config.PanUser, name string) *aliyunpan_web.AlbumEntity {
records, err := activeUser.PanClient().WebapiPanClient().AlbumListGetAll(&aliyunpan_web.AlbumListParam{})
if err != nil {
fmt.Printf("获取相簿列表失败: %s\n", err)
return nil
@ -431,7 +432,7 @@ func RunAlbumRename(name, newName string) {
if record == nil {
return
}
_, err := activeUser.PanClient().WebapiPanClient().AlbumEdit(&aliyunpan.AlbumEditParam{
_, err := activeUser.PanClient().WebapiPanClient().AlbumEdit(&aliyunpan_web.AlbumEditParam{
AlbumId: record.AlbumId,
Description: record.Description,
Name: newName,
@ -456,7 +457,7 @@ func RunAlbumListFile(name string) {
return
}
fileList, er := activeUser.PanClient().WebapiPanClient().AlbumListFileGetAll(&aliyunpan.AlbumListFileParam{
fileList, er := activeUser.PanClient().WebapiPanClient().AlbumListFileGetAll(&aliyunpan_web.AlbumListFileParam{
AlbumId: record.AlbumId,
})
if er != nil {
@ -482,14 +483,14 @@ func RunAlbumRmFile(name string, nameList []string) {
return
}
fileList, er := activeUser.PanClient().WebapiPanClient().AlbumListFileGetAll(&aliyunpan.AlbumListFileParam{
fileList, er := activeUser.PanClient().WebapiPanClient().AlbumListFileGetAll(&aliyunpan_web.AlbumListFileParam{
AlbumId: album.AlbumId,
})
if er != nil {
fmt.Printf("获取相簿文件列表失败:%s\n", er)
return
}
param := &aliyunpan.AlbumDeleteFileParam{
param := &aliyunpan_web.AlbumDeleteFileParam{
AlbumId: album.AlbumId,
DriveFileList: []aliyunpan.FileBatchActionParam{},
}
@ -545,7 +546,7 @@ func RunAlbumAddFile(albumName string, filePathList []string, filterOption Album
}
fmt.Printf("正在获取增加的文件信息,该操作可能会非常耗费时间,请耐心等待...\n")
param := &aliyunpan.AlbumAddFileParam{
param := &aliyunpan_web.AlbumAddFileParam{
AlbumId: album.AlbumId,
DriveFileList: []aliyunpan.FileBatchActionParam{},
}
@ -713,7 +714,7 @@ func RunAlbumDownloadFile(albumNames []string, options *DownloadOptions) {
continue
}
// 获取相簿下的所有文件
fileList, er := activeUser.PanClient().WebapiPanClient().AlbumListFileGetAll(&aliyunpan.AlbumListFileParam{
fileList, er := activeUser.PanClient().WebapiPanClient().AlbumListFileGetAll(&aliyunpan_web.AlbumListFileParam{
AlbumId: record.AlbumId,
})
if er != nil {

View File

@ -17,6 +17,7 @@ import (
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/cmder/cmdtable"
"github.com/tickstep/aliyunpan/internal/config"
@ -157,7 +158,7 @@ func CmdRecycle() cli.Command {
// RunRecycleList 执行列出回收站文件列表
func RunRecycleList(driveId string) {
panClient := GetActivePanClient()
fdl, err := panClient.WebapiPanClient().RecycleBinFileListGetAll(&aliyunpan.RecycleBinFileListParam{
fdl, err := panClient.WebapiPanClient().RecycleBinFileListGetAll(&aliyunpan_web.RecycleBinFileListParam{
DriveId: driveId,
Limit: 100,
})
@ -245,7 +246,7 @@ func RunRecycleClear(driveId string) {
panClient := GetActivePanClient()
// 提交清空回收站异步任务
r, err := panClient.WebapiPanClient().RecycleBinFileClear(&aliyunpan.RecycleBinFileClearParam{
r, err := panClient.WebapiPanClient().RecycleBinFileClear(&aliyunpan_web.RecycleBinFileClearParam{
DriveId: driveId,
})
if err != nil {
@ -254,7 +255,7 @@ func RunRecycleClear(driveId string) {
}
for i := 0; i < 10; i++ {
ar, err1 := panClient.WebapiPanClient().AsyncTaskQueryStatus(&aliyunpan.AsyncTaskQueryStatusParam{
ar, err1 := panClient.WebapiPanClient().AsyncTaskQueryStatus(&aliyunpan_web.AsyncTaskQueryStatusParam{
AsyncTaskId: r.AsyncTaskId,
})
if err1 != nil {

View File

@ -15,10 +15,10 @@ package command
import (
"fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"path"
"strings"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan/internal/config"
"github.com/urfave/cli"
)
@ -113,8 +113,8 @@ func RunSave(driveId string, args ...string) {
list.NextMarker = list2.NextMarker
}
var params []*aliyunpan.FileSaveParam
files := make(map[string]*aliyunpan.ListByShareItem)
var params []*aliyunpan_web.FileSaveParam
files := make(map[string]*aliyunpan_web.ListByShareItem)
for _, item := range list.Items {
if item.FileExtension != "" {
fmt.Println(" ", item.Name)
@ -123,7 +123,7 @@ func RunSave(driveId string, args ...string) {
}
files[item.FileID] = item
params = append(params, &aliyunpan.FileSaveParam{
params = append(params, &aliyunpan_web.FileSaveParam{
ShareID: shareID,
FileId: item.FileID,
AutoRename: true,

View File

@ -18,6 +18,7 @@ import (
"fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/cmder/cmdtable"
"github.com/tickstep/aliyunpan/internal/config"
@ -268,7 +269,7 @@ func RunShareSet(modeFlag, driveId string, paths []string, expiredTime string, s
if modeFlag == "3" {
// 快传
r, err1 := panClient.WebapiPanClient().FastShareLinkCreate(aliyunpan.FastShareCreateParam{
r, err1 := panClient.WebapiPanClient().FastShareLinkCreate(aliyunpan_web.FastShareCreateParam{
DriveId: driveId,
FileIdList: fidList,
})
@ -285,7 +286,7 @@ func RunShareSet(modeFlag, driveId string, paths []string, expiredTime string, s
fmt.Printf("链接:%s\n", r.ShareUrl)
} else {
// 分享
r, err1 := panClient.WebapiPanClient().ShareLinkCreate(aliyunpan.ShareCreateParam{
r, err1 := panClient.WebapiPanClient().ShareLinkCreate(aliyunpan_web.ShareCreateParam{
DriveId: driveId,
SharePwd: sharePwd,
Expiration: expiredTime,

View File

@ -16,6 +16,7 @@ package command
import (
"fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/internal/config"
"github.com/tickstep/aliyunpan/internal/functions/panlogin"
"github.com/tickstep/aliyunpan/internal/plugins"
@ -126,12 +127,12 @@ func UnescapeStr(s string) string {
return r
}
func NewWebLoginToken(accessToken string, expired int64) aliyunpan.WebLoginToken {
func NewWebLoginToken(accessToken string, expired int64) aliyunpan_web.WebLoginToken {
webapiToken := &config.PanClientToken{
AccessToken: accessToken,
Expired: expired,
}
return aliyunpan.WebLoginToken{
return aliyunpan_web.WebLoginToken{
AccessTokenType: "Bearer",
AccessToken: webapiToken.AccessToken,
RefreshToken: "",

View File

@ -16,6 +16,7 @@ package command
import (
"fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/cmder/cmdtable"
"github.com/tickstep/aliyunpan/internal/config"
"github.com/urfave/cli"
@ -110,7 +111,7 @@ func RunXCopy(srcDriveId, dstDriveId string, paths ...string) {
copyFileParamList = append(copyFileParamList, mfi.FileId)
cacheCleanPaths = append(cacheCleanPaths, path.Dir(mfi.Path))
}
fccr, er := activeUser.PanClient().WebapiPanClient().FileCrossDriveCopy(&aliyunpan.FileCrossCopyParam{
fccr, er := activeUser.PanClient().WebapiPanClient().FileCrossDriveCopy(&aliyunpan_web.FileCrossCopyParam{
FromDriveId: srcDriveId,
FromFileIds: copyFileParamList,
ToDriveId: dstDriveId,

View File

@ -1,28 +1,28 @@
package config
import (
"github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan_open"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
)
type (
// PanClient 云盘客户端
PanClient struct {
// 网页WEB接口客户端
webapiPanClient *aliyunpan.PanClient
webapiPanClient *aliyunpan_web.PanClient
// 阿里openapi接口客户端
openapiPanClient *aliyunpan_open.OpenPanClient
}
)
func NewPanClient(webClient *aliyunpan.PanClient, openClient *aliyunpan_open.OpenPanClient) *PanClient {
func NewPanClient(webClient *aliyunpan_web.PanClient, openClient *aliyunpan_open.OpenPanClient) *PanClient {
return &PanClient{
webapiPanClient: webClient,
openapiPanClient: openClient,
}
}
func (p *PanClient) WebapiPanClient() *aliyunpan.PanClient {
func (p *PanClient) WebapiPanClient() *aliyunpan_web.PanClient {
return p.webapiPanClient
}
@ -30,7 +30,7 @@ func (p *PanClient) OpenapiPanClient() *aliyunpan_open.OpenPanClient {
return p.openapiPanClient
}
func (p *PanClient) UpdateClient(openClient *aliyunpan_open.OpenPanClient, webClient *aliyunpan.PanClient) {
func (p *PanClient) UpdateClient(openClient *aliyunpan_open.OpenPanClient, webClient *aliyunpan_web.PanClient) {
p.webapiPanClient = webClient
p.openapiPanClient = openClient
}

View File

@ -19,6 +19,7 @@ import (
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
"github.com/tickstep/aliyunpan-api/aliyunpan_open"
"github.com/tickstep/aliyunpan-api/aliyunpan_open/openapi"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/internal/functions/panlogin"
"github.com/tickstep/library-go/expires/cachemap"
"github.com/tickstep/library-go/logger"
@ -162,22 +163,22 @@ doWebLoginAct:
// setup webapi client
var webUserInfo *aliyunpan.UserInfo
var err2 *apierror.ApiError
var webPanClient *aliyunpan.PanClient
var webPanClient *aliyunpan_web.PanClient
if webapiToken != nil && webapiToken.AccessToken != "" {
appConfig := aliyunpan.AppConfig{
appConfig := aliyunpan_web.AppConfig{
AppId: "25dzX3vbYqktVxyX",
DeviceId: deviceId,
UserId: userId,
Nonce: 0,
PublicKey: "",
}
webPanClient = aliyunpan.NewPanClient(aliyunpan.WebLoginToken{
webPanClient = aliyunpan_web.NewPanClient(aliyunpan_web.WebLoginToken{
AccessTokenType: "Bearer",
AccessToken: webapiToken.AccessToken,
RefreshToken: "",
ExpiresIn: 7200,
ExpireTime: webapiToken.GetExpiredTimeCstStr(),
}, aliyunpan.AppLoginToken{}, appConfig, aliyunpan.SessionConfig{
}, aliyunpan_web.AppLoginToken{}, appConfig, aliyunpan_web.SessionConfig{
DeviceName: deviceName,
ModelName: "Windows网页版",
})