@@ -4,9 +4,12 @@ import (
44 "context"
55 "errors"
66 "fmt"
7+ "net/url"
78 "os"
89 "path"
910 "path/filepath"
11+ "strconv"
12+ "strings"
1013)
1114
1215type MoveLocalFile struct {
@@ -62,14 +65,30 @@ func (j *MoveRemoteFile) String() string {
6265}
6366
6467func (j * MoveRemoteFile ) Run (ctx context.Context ) error {
65- dir := path .Dir (j .toRelpath )
68+ dir , name := path .Split (j .toRelpath )
6669 parentID , err := dirCache .Mkdirp (ctx , dir )
6770 if err != nil {
6871 return err
6972 }
70- err = client . Files . Move (ctx , parentID , j .remoteFile .putioFile .ID )
73+ err = moveRemoteFile (ctx , parentID , j .remoteFile .putioFile .ID , name )
7174 if err != nil {
7275 return err
7376 }
7477 return j .state .Move (j .toRelpath )
7578}
79+
80+ func moveRemoteFile (ctx context.Context , parentID , fileID int64 , name string ) error {
81+ params := url.Values {}
82+ params .Set ("file_id" , strconv .FormatInt (fileID , 10 ))
83+ params .Set ("parent_id" , strconv .FormatInt (parentID , 10 ))
84+ params .Set ("name" , name )
85+
86+ req , err := client .NewRequest (ctx , "POST" , "/v2/files/move" , strings .NewReader (params .Encode ()))
87+ if err != nil {
88+ return err
89+ }
90+ req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
91+
92+ _ , err = client .Do (req , nil )
93+ return err
94+ }
0 commit comments