From b567880ff05376412b75576348c675da178d72c2 Mon Sep 17 00:00:00 2001 From: zhouxin Date: Sat, 12 Jun 2021 09:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=98=BF=E9=87=8C=E7=BD=91?= =?UTF-8?q?=E7=9B=98API=E5=88=86=E9=A1=B5=E4=B8=8D=E8=83=BD=E8=B6=85?= =?UTF-8?q?=E8=BF=87200=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zxbu/webdavteambition/model/Page.java | 10 +++---- .../model/result/TFileListResult.java | 9 ++++++ .../store/AliYunDriverClientService.java | 30 ++++++++++++------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/github/zxbu/webdavteambition/model/Page.java b/src/main/java/com/github/zxbu/webdavteambition/model/Page.java index 091741d..1f67313 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/model/Page.java +++ b/src/main/java/com/github/zxbu/webdavteambition/model/Page.java @@ -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() { diff --git a/src/main/java/com/github/zxbu/webdavteambition/model/result/TFileListResult.java b/src/main/java/com/github/zxbu/webdavteambition/model/result/TFileListResult.java index e855577..0973279 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/model/result/TFileListResult.java +++ b/src/main/java/com/github/zxbu/webdavteambition/model/result/TFileListResult.java @@ -4,6 +4,7 @@ import java.util.List; public class TFileListResult { private List items; + private String next_marker; public List getItems() { return items; @@ -12,4 +13,12 @@ public class TFileListResult { public void setItems(List items) { this.items = items; } + + public String getNext_marker() { + return next_marker; + } + + public void setNext_marker(String next_marker) { + this.next_marker = next_marker; + } } diff --git a/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java b/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java index 944e22c..ce28b9e 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java +++ b/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java @@ -59,17 +59,7 @@ public class AliYunDriverClientService { } private Set 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 tFileListResult = JsonUtil.readValue(json, new TypeReference>() { - }); - List tFileList = tFileListResult.getItems(); + List tFileList = fileListFromApi(nodeId, null, new ArrayList<>()); tFileList.sort(Comparator.comparing(TFile::getUpdated_at).reversed()); Set tFileSets = new LinkedHashSet<>(); for (TFile tFile : tFileList) { @@ -81,6 +71,24 @@ public class AliYunDriverClientService { return tFileSets; } + private List fileListFromApi(String nodeId, String marker, List 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 tFileListResult = JsonUtil.readValue(json, new TypeReference>() { + }); + all.addAll(tFileListResult.getItems()); + if (!StringUtils.hasLength(tFileListResult.getNext_marker())) { + return all; + } + return fileListFromApi(nodeId, tFileListResult.getNext_marker(), all); + } + private Map toMap(Object o) { try {