修复阿里网盘API分页不能超过200的BUG

This commit is contained in:
zhouxin 2021-06-12 09:31:02 +08:00
parent ce5e68407d
commit b567880ff0
3 changed files with 33 additions and 16 deletions

View File

@ -1,17 +1,17 @@
package com.github.zxbu.webdavteambition.model;
public class Page {
private int offset;
private String marker;
private int limit;
private String order_by;
private String order_direction;
public int getOffset() {
return offset;
public String getMarker() {
return marker;
}
public void setOffset(int offset) {
this.offset = offset;
public void setMarker(String marker) {
this.marker = marker;
}
public int getLimit() {

View File

@ -4,6 +4,7 @@ import java.util.List;
public class TFileListResult<T> {
private List<T> items;
private String next_marker;
public List<T> getItems() {
return items;
@ -12,4 +13,12 @@ public class TFileListResult<T> {
public void setItems(List<T> items) {
this.items = items;
}
public String getNext_marker() {
return next_marker;
}
public void setNext_marker(String next_marker) {
this.next_marker = next_marker;
}
}

View File

@ -59,17 +59,7 @@ public class AliYunDriverClientService {
}
private Set<TFile> getTFiles2(String nodeId) {
FileListRequest listQuery = new FileListRequest();
listQuery.setOffset(0);
listQuery.setLimit(10000);
listQuery.setOrder_by("updated_at");
listQuery.setOrder_direction("DESC");
listQuery.setDrive_id(client.getDriveId());
listQuery.setParent_file_id(nodeId);
String json = client.post("/file/list", listQuery);
TFileListResult<TFile> tFileListResult = JsonUtil.readValue(json, new TypeReference<TFileListResult<TFile>>() {
});
List<TFile> tFileList = tFileListResult.getItems();
List<TFile> tFileList = fileListFromApi(nodeId, null, new ArrayList<>());
tFileList.sort(Comparator.comparing(TFile::getUpdated_at).reversed());
Set<TFile> tFileSets = new LinkedHashSet<>();
for (TFile tFile : tFileList) {
@ -81,6 +71,24 @@ public class AliYunDriverClientService {
return tFileSets;
}
private List<TFile> fileListFromApi(String nodeId, String marker, List<TFile> all) {
FileListRequest listQuery = new FileListRequest();
listQuery.setMarker(marker);
listQuery.setLimit(100);
listQuery.setOrder_by("updated_at");
listQuery.setOrder_direction("DESC");
listQuery.setDrive_id(client.getDriveId());
listQuery.setParent_file_id(nodeId);
String json = client.post("/file/list", listQuery);
TFileListResult<TFile> tFileListResult = JsonUtil.readValue(json, new TypeReference<TFileListResult<TFile>>() {
});
all.addAll(tFileListResult.getItems());
if (!StringUtils.hasLength(tFileListResult.getNext_marker())) {
return all;
}
return fileListFromApi(nodeId, tFileListResult.getNext_marker(), all);
}
private Map<String, String> toMap(Object o) {
try {