修复阿里网盘API分页不能超过200的BUG
This commit is contained in:
parent
ce5e68407d
commit
b567880ff0
|
@ -1,17 +1,17 @@
|
||||||
package com.github.zxbu.webdavteambition.model;
|
package com.github.zxbu.webdavteambition.model;
|
||||||
|
|
||||||
public class Page {
|
public class Page {
|
||||||
private int offset;
|
private String marker;
|
||||||
private int limit;
|
private int limit;
|
||||||
private String order_by;
|
private String order_by;
|
||||||
private String order_direction;
|
private String order_direction;
|
||||||
|
|
||||||
public int getOffset() {
|
public String getMarker() {
|
||||||
return offset;
|
return marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOffset(int offset) {
|
public void setMarker(String marker) {
|
||||||
this.offset = offset;
|
this.marker = marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLimit() {
|
public int getLimit() {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class TFileListResult<T> {
|
public class TFileListResult<T> {
|
||||||
private List<T> items;
|
private List<T> items;
|
||||||
|
private String next_marker;
|
||||||
|
|
||||||
public List<T> getItems() {
|
public List<T> getItems() {
|
||||||
return items;
|
return items;
|
||||||
|
@ -12,4 +13,12 @@ public class TFileListResult<T> {
|
||||||
public void setItems(List<T> items) {
|
public void setItems(List<T> items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNext_marker() {
|
||||||
|
return next_marker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNext_marker(String next_marker) {
|
||||||
|
this.next_marker = next_marker;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,17 +59,7 @@ public class AliYunDriverClientService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<TFile> getTFiles2(String nodeId) {
|
private Set<TFile> getTFiles2(String nodeId) {
|
||||||
FileListRequest listQuery = new FileListRequest();
|
List<TFile> tFileList = fileListFromApi(nodeId, null, new ArrayList<>());
|
||||||
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();
|
|
||||||
tFileList.sort(Comparator.comparing(TFile::getUpdated_at).reversed());
|
tFileList.sort(Comparator.comparing(TFile::getUpdated_at).reversed());
|
||||||
Set<TFile> tFileSets = new LinkedHashSet<>();
|
Set<TFile> tFileSets = new LinkedHashSet<>();
|
||||||
for (TFile tFile : tFileList) {
|
for (TFile tFile : tFileList) {
|
||||||
|
@ -81,6 +71,24 @@ public class AliYunDriverClientService {
|
||||||
return tFileSets;
|
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) {
|
private Map<String, String> toMap(Object o) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue