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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,6 +16,7 @@ package command
import ( import (
"fmt" "fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan" "github.com/tickstep/aliyunpan-api/aliyunpan"
"github.com/tickstep/aliyunpan-api/aliyunpan_web"
"github.com/tickstep/aliyunpan/cmder/cmdtable" "github.com/tickstep/aliyunpan/cmder/cmdtable"
"github.com/tickstep/aliyunpan/internal/config" "github.com/tickstep/aliyunpan/internal/config"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -110,7 +111,7 @@ func RunXCopy(srcDriveId, dstDriveId string, paths ...string) {
copyFileParamList = append(copyFileParamList, mfi.FileId) copyFileParamList = append(copyFileParamList, mfi.FileId)
cacheCleanPaths = append(cacheCleanPaths, path.Dir(mfi.Path)) 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, FromDriveId: srcDriveId,
FromFileIds: copyFileParamList, FromFileIds: copyFileParamList,
ToDriveId: dstDriveId, ToDriveId: dstDriveId,

View File

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

View File

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