From cce9f787a8efb9e7cef16fbf74b5941e7e94ec8c Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Mon, 26 Jun 2023 21:56:16 +0200 Subject: [PATCH] Add MoveFile code --- folder.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/folder.go b/folder.go index d3c2a76..34e5388 100644 --- a/folder.go +++ b/folder.go @@ -228,6 +228,30 @@ func (protonDrive *ProtonDrive) CreateNewFolder(ctx context.Context, parentLink return createFolderResp.ID, nil } +func (protonDrive *ProtonDrive) MoveFileByID(ctx context.Context, srcLinkID, dstParentLinkID string, dstName string) error { + srcLink, err := protonDrive.c.GetLink(ctx, protonDrive.MainShare.ShareID, srcLinkID) + if err != nil { + return err + } + if srcLink.State != proton.LinkStateActive { + return ErrLinkMustBeActive + } + + dstParentLink, err := protonDrive.c.GetLink(ctx, protonDrive.MainShare.ShareID, dstParentLinkID) + if err != nil { + return err + } + if dstParentLink.State != proton.LinkStateActive { + return ErrLinkMustBeActive + } + + return protonDrive.MoveFile(ctx, &srcLink, &dstParentLink, dstName) +} + +func (protonDrive *ProtonDrive) MoveFile(ctx context.Context, srcLink *proton.Link, dstParentLink *proton.Link, dstName string) error { + return protonDrive.MoveFolder(ctx, srcLink, dstParentLink, dstName) +} + func (protonDrive *ProtonDrive) MoveFolderByID(ctx context.Context, srcLinkID, dstParentLinkID, dstName string) error { srcLink, err := protonDrive.c.GetLink(ctx, protonDrive.MainShare.ShareID, srcLinkID) if err != nil { @@ -248,11 +272,11 @@ func (protonDrive *ProtonDrive) MoveFolderByID(ctx context.Context, srcLinkID, d return protonDrive.MoveFolder(ctx, &srcLink, &dstParentLink, dstName) } -func (protonDrive *ProtonDrive) MoveFile(ctx context.Context, srcLink *proton.Link, dstParentLink *proton.Link, dstName string) error { - return protonDrive.MoveFolder(ctx, srcLink, dstParentLink, dstName) +func (protonDrive *ProtonDrive) MoveFolder(ctx context.Context, srcLink *proton.Link, dstParentLink *proton.Link, dstName string) error { + return protonDrive.moveLink(ctx, srcLink, dstParentLink, dstName) } -func (protonDrive *ProtonDrive) MoveFolder(ctx context.Context, srcLink *proton.Link, dstParentLink *proton.Link, dstName string) error { +func (protonDrive *ProtonDrive) moveLink(ctx context.Context, srcLink *proton.Link, dstParentLink *proton.Link, dstName string) error { // we are moving the srcLink to under dstParentLink, with name dstName req := proton.MoveLinkReq{ ParentLinkID: dstParentLink.LinkID,