diff --git a/job_move.go b/job_move.go index 2e5ba50..bfa4e26 100644 --- a/job_move.go +++ b/job_move.go @@ -4,9 +4,12 @@ import ( "context" "errors" "fmt" + "net/url" "os" "path" "path/filepath" + "strconv" + "strings" ) type MoveLocalFile struct { @@ -62,14 +65,30 @@ func (j *MoveRemoteFile) String() string { } func (j *MoveRemoteFile) Run(ctx context.Context) error { - dir := path.Dir(j.toRelpath) + dir, name := path.Split(j.toRelpath) parentID, err := dirCache.Mkdirp(ctx, dir) if err != nil { return err } - err = client.Files.Move(ctx, parentID, j.remoteFile.putioFile.ID) + err = moveRemoteFile(ctx, parentID, j.remoteFile.putioFile.ID, name) if err != nil { return err } return j.state.Move(j.toRelpath) } + +func moveRemoteFile(ctx context.Context, parentID, fileID int64, name string) error { + params := url.Values{} + params.Set("file_id", strconv.FormatInt(fileID, 10)) + params.Set("parent_id", strconv.FormatInt(parentID, 10)) + params.Set("name", name) + + req, err := client.NewRequest(ctx, "POST", "/v2/files/move", strings.NewReader(params.Encode())) + if err != nil { + return err + } + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + + _, err = client.Do(req, nil) + return err +}