Skip to content

Commit

Permalink
optimize: file delete logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao committed Jun 28, 2023
1 parent 2c1a64c commit 0f419d5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
Binary file modified lib/api-0.3.0-sources.jar
Binary file not shown.
Binary file modified lib/api-0.3.0.jar
Binary file not shown.
26 changes: 26 additions & 0 deletions src/main/java/run/ikaros/plugin/baidupan/BaiDuPanClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,30 @@ private void downloadFileByInfo(Path targetDirPath, FileInfo fileInfo)


}

public void delete(String path) {
delete(path, false);
}

public void delete(String path, boolean isSync) {
Assert.notNull(path, "'path' must not null.");

UriComponents uriComponents =
UriComponentsBuilder.fromHttpUrl("http://pan.baidu.com/rest/2.0/xpan/file")
.queryParam("method", "filemanager")
.queryParam("access_token", accessToken)
.queryParam("opera", "delete").build();


MultiValueMap<String, Object> bodyMap = new LinkedMultiValueMap<>();
bodyMap.put("async", Collections.singletonList(isSync ? 0 : 2));
bodyMap.put("filelist", Collections.singletonList(List.of(path)));

Map map = restTemplate.postForEntity(uriComponents.toUri(), bodyMap, Map.class).getBody();
if(map != null && map.containsKey("errno") && !"0".equals(map.get("errno"))) {
log.warn("delete remote file fail, result:{} ", map);
} else {
log.debug("delete remote file result: {}", map);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void pull(Path targetDirPath, List<String> fsIdList) {
}

@Override
public void delete(Path path) {

public void delete(String path) {
client.delete(path, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package run.ikaros.plugin.baidupan.result;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;
import lombok.Data;

@Data
public class FileDeleteResult {
private List<FileInfo> list;
@JsonProperty("taskid")
private Long taskId;
}

0 comments on commit 0f419d5

Please sign in to comment.