Skip to content
This repository was archived by the owner on Jul 21, 2024. It is now read-only.

Commit d8f6e46

Browse files
committed
Api 1.0.4 App 3.0.8 Workaround for OpenApi QPS rate limit
1 parent acd9cd4 commit d8f6e46

File tree

17 files changed

+141
-33
lines changed

17 files changed

+141
-33
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,18 @@ implementation "com.squareup.okhttp3:logging-interceptor:3.12.13" //api19
146146
implementation "com.google.code.gson:gson:2.8.9"
147147
148148
//主要
149-
implementation "net.xdow:aliyundrive-sdk-openapi:1.0.3"
150-
implementation "net.xdow:aliyundrive-sdk-webapi:1.0.3"
149+
implementation "net.xdow:aliyundrive-sdk-openapi:1.0.4"
150+
implementation "net.xdow:aliyundrive-sdk-webapi:1.0.4"
151151
152152
//可选
153-
implementation "net.xdow:webdav:1.0.3"
154-
implementation "net.xdow:webdav-jakarta:1.0.3"
155-
implementation "net.xdow:webdav-javax:1.0.3"
156-
implementation "net.xdow:aliyundrive-webdav-internal:1.0.3"
157-
implementation "net.xdow:aliyundrive-android-core:1.0.3"
158-
implementation "net.xdow:jap-http:1.0.3"
159-
implementation "net.xdow:jap-http-jakarta-adapter:1.0.3"
160-
implementation "net.xdow:jap-http-javax-adapter:1.0.3"
153+
implementation "net.xdow:webdav:1.0.4"
154+
implementation "net.xdow:webdav-jakarta:1.0.4"
155+
implementation "net.xdow:webdav-javax:1.0.4"
156+
implementation "net.xdow:aliyundrive-webdav-internal:1.0.4"
157+
implementation "net.xdow:aliyundrive-android-core:1.0.4"
158+
implementation "net.xdow:jap-http:1.0.4"
159+
implementation "net.xdow:jap-http-jakarta-adapter:1.0.4"
160+
implementation "net.xdow:jap-http-javax-adapter:1.0.4"
161161
```
162162
## 基础用法
163163
```java

aliyundrive-android-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515
apply plugin: 'com.android.library'
1616

1717
group 'net.xdow'
18-
version '1.0.3'
18+
version '1.0.4'
1919
description 'AliyunDrive Webdav Android Core'
2020

2121
repositories {

aliyundrive-sdk-openapi/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'AliyunDrive OpenApi SDK'
88

99
java {

aliyundrive-sdk-openapi/src/main/java/net/xdow/aliyundrive/impl/AliyunDriveOpenApiImplV1.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,24 @@ public Response intercept(Chain chain) throws IOException {
6969
.dns(new Dns() {
7070
@Override
7171
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
72-
return Arrays.asList(Address.getAllByName(hostname));
72+
List<InetAddress> list = new ArrayList<>();
73+
UnknownHostException unknownHostException = null;
74+
try {
75+
list.addAll(Dns.SYSTEM.lookup(hostname));
76+
} catch (UnknownHostException e) {
77+
unknownHostException = e;
78+
}
79+
try {
80+
list.addAll(Arrays.asList(Address.getAllByName(hostname)));
81+
} catch (UnknownHostException e) {
82+
if (unknownHostException == null) {
83+
unknownHostException = e;
84+
}
85+
}
86+
if (list.size() <= 0 && unknownHostException != null) {
87+
throw unknownHostException;
88+
}
89+
return list;
7390
}
7491
})
7592
.followRedirects(true)

aliyundrive-sdk-webapi/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'AliyunDrive WebApi SDK'
88

99
java {

aliyundrive-sdk-webapi/src/main/java/net/xdow/aliyundrive/webapi/impl/AliyunDriveWebApiImplV1.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,24 @@ public Request authenticate(Route route, Response response) throws IOException {
109109
.dns(new Dns() {
110110
@Override
111111
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
112-
return Arrays.asList(Address.getAllByName(hostname));
112+
List<InetAddress> list = new ArrayList<>();
113+
UnknownHostException unknownHostException = null;
114+
try {
115+
list.addAll(Dns.SYSTEM.lookup(hostname));
116+
} catch (UnknownHostException e) {
117+
unknownHostException = e;
118+
}
119+
try {
120+
list.addAll(Arrays.asList(Address.getAllByName(hostname)));
121+
} catch (UnknownHostException e) {
122+
if (unknownHostException == null) {
123+
unknownHostException = e;
124+
}
125+
}
126+
if (list.size() <= 0 && unknownHostException != null) {
127+
throw unknownHostException;
128+
}
129+
return list;
113130
}
114131
})
115132
.followRedirects(true)

aliyundrive-webdav-internal/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'AliyunDrive Webdav internal'
88

99
java {

aliyundrive-webdav-internal/src/main/java/com/github/zxbu/webdavteambition/config/AliyunDriveProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class AliyunDriveProperties {
3131
private transient String clientId;
3232

3333
private transient String authorizationCode;
34-
private transient String aliyunAccessTokenUrl = "https://adrive.xdow.net/oauth/access_token?code=%s&refresh_token=%s";
34+
private transient String aliyunAccessTokenUrl = "https://adrive.xdow.net/oauth/access_token?code=%s&refresh_token=%s&ver=1.0.4";
3535
private transient String aliyunAuthorizeUrl = "https://adrive.xdow.net/oauth/authorize?redirect_uri=%s";
3636

3737
private transient Auth auth = new Auth();

aliyundrive-webdav-internal/src/main/java/com/github/zxbu/webdavteambition/store/AliyunDriveClientService.java

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ public Set<AliyunDriveFileInfo> load(String key) throws Exception {
5656
return AliyunDriveClientService.this.getTFiles2(key);
5757
}
5858
});
59+
60+
private LoadingCache<String, AliyunDriveResponse.FileGetDownloadUrlInfo> tFileDownloadUrlCache = CacheBuilder.newBuilder()
61+
.initialCapacity(128)
62+
.maximumSize(10240)
63+
.expireAfterWrite(AliyunDriveConstant.MAX_DOWNLOAD_URL_EXPIRE_TIME_SEC, TimeUnit.SECONDS)
64+
.build(new CacheLoader<String, AliyunDriveResponse.FileGetDownloadUrlInfo>() {
65+
@Override
66+
public AliyunDriveResponse.FileGetDownloadUrlInfo load(String key) throws Exception {
67+
return fileGetDownloadUrlInternal(key);
68+
}
69+
});
5970
private final T mAliyunDrive;
6071

6172
public AliyunDriveClientService(Class<? extends IAliyunDrive> aliyunDriveCls, AliyunDriveProperties aliyunDriveProperties) {
@@ -124,6 +135,24 @@ private List<AliyunDriveFileInfo> fileListFromApi(String nodeId, String marker,
124135
query.setOrderBy(AliyunDriveEnum.OrderBy.UpdatedAt);
125136
query.setOrderDirection(AliyunDriveEnum.OrderDirection.Desc);
126137
AliyunDriveResponse.FileListInfo res = this.mAliyunDrive.fileList(query).execute();
138+
if (res.isError()) {
139+
if ("TooManyRequests".equals(res.getCode())) {
140+
try {
141+
TimeUnit.SECONDS.sleep(6);
142+
} catch (InterruptedException e) {
143+
}
144+
res = this.mAliyunDrive.fileList(query).execute();
145+
}
146+
}
147+
if (res.isError()) {
148+
if ("TooManyRequests".equals(res.getCode())) {
149+
try {
150+
TimeUnit.SECONDS.sleep(6);
151+
} catch (InterruptedException e) {
152+
}
153+
res = this.mAliyunDrive.fileList(query).execute();
154+
}
155+
}
127156
all.addAll(res.getItems());
128157
String nextMarker = res.getNextMarker();
129158
if (StringUtils.isEmpty(nextMarker)) {
@@ -398,16 +427,12 @@ public AliyunDriveFileInfo getTFileByPath(String path) {
398427

399428
public Response download(String path, JapHttpRequest request, long size) {
400429
AliyunDriveFileInfo file = getTFileByPath(path);
401-
AliyunDriveRequest.FileGetDownloadUrlInfo query = new AliyunDriveRequest.FileGetDownloadUrlInfo(
402-
getDefaultDriveId(), file.getFileId()
403-
);
404-
query.setExpireSec(AliyunDriveConstant.MAX_DOWNLOAD_URL_EXPIRE_TIME_SEC);
405-
AliyunDriveResponse.FileGetDownloadUrlInfo res = this.mAliyunDrive.fileGetDownloadUrl(query).execute();
430+
String range = extractRangeHeader(request, size);
431+
String ifRange = extractIfRangeHeader(request);
432+
AliyunDriveResponse.FileGetDownloadUrlInfo res = fileGetDownloadUrlInfo(file.getFileId());
406433
if (res.isError()) {
407434
throw new WebdavException(new WebdavException(res.getCode(), res.getMessage()));
408435
}
409-
String range = extractRangeHeader(request, size);
410-
String ifRange = extractIfRangeHeader(request);
411436
String url = res.getUrl().replaceAll("^https://", "http://");
412437
try {
413438
return this.mAliyunDrive.download(url, range, ifRange).execute();
@@ -416,6 +441,55 @@ public Response download(String path, JapHttpRequest request, long size) {
416441
}
417442
}
418443

444+
private synchronized AliyunDriveResponse.FileGetDownloadUrlInfo fileGetDownloadUrlInfo(String fileId) {
445+
AliyunDriveResponse.FileGetDownloadUrlInfo res;
446+
try {
447+
res = tFileDownloadUrlCache.get(fileId);
448+
Date expirationDate = res.getExpiration();
449+
if (expirationDate != null && new Date().after(expirationDate)) {
450+
tFileDownloadUrlCache.invalidate(fileId);
451+
res = tFileDownloadUrlCache.get(fileId);
452+
}
453+
return res;
454+
} catch (ExecutionException e) {
455+
res = new AliyunDriveResponse.FileGetDownloadUrlInfo();
456+
res.setCode(e.getMessage());
457+
res.setMessage(e.toString());
458+
return res;
459+
}
460+
}
461+
462+
private synchronized AliyunDriveResponse.FileGetDownloadUrlInfo fileGetDownloadUrlInternal(String fileId) {
463+
AliyunDriveRequest.FileGetDownloadUrlInfo query = new AliyunDriveRequest.FileGetDownloadUrlInfo(
464+
getDefaultDriveId(), fileId
465+
);
466+
query.setExpireSec(AliyunDriveConstant.MAX_DOWNLOAD_URL_EXPIRE_TIME_SEC);
467+
AliyunDriveResponse.FileGetDownloadUrlInfo res = this.mAliyunDrive.fileGetDownloadUrl(query).execute();
468+
if (res.isError()) {
469+
if ("TooManyRequests".equals(res.getCode())) {
470+
try {
471+
TimeUnit.SECONDS.sleep(6);
472+
} catch (InterruptedException e) {
473+
}
474+
res = this.mAliyunDrive.fileGetDownloadUrl(query).execute();
475+
}
476+
}
477+
if (res.isError()) {
478+
if ("TooManyRequests".equals(res.getCode())) {
479+
try {
480+
TimeUnit.SECONDS.sleep(6);
481+
} catch (InterruptedException e) {
482+
}
483+
res = this.mAliyunDrive.fileGetDownloadUrl(query).execute();
484+
}
485+
}
486+
if (res.isError()) {
487+
LOGGER.error("fileGetDownloadUrlInternal code: " + res.getCode() + " message: " + res.getMessage());
488+
return null;
489+
}
490+
return res;
491+
}
492+
419493
private String extractIfRangeHeader(JapHttpRequest request) {
420494
String ifRange = request.getHeader("if-range");
421495
if (ifRange == null) {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'com.github'
9-
version '3.0.6'
9+
version '3.0.8'
1010
sourceCompatibility = '17'
1111

1212
configurations {

jap-http-adapter/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<dependency>
1616
<groupId>com.fujieid.jap.http.adapter</groupId>
1717
<artifactId>jap-http-jakarta-adapter</artifactId>
18-
<version>1.0.3</version>
18+
<version>1.0.4</version>
1919
</dependency>
2020
```
2121
2. 使用适配器重新构造
@@ -39,7 +39,7 @@ new JakartaResponseAdapter(HttpServletResponse);
3939
<dependency>
4040
<groupId>com.fujieid.jap.http.adapter</groupId>
4141
<artifactId>jap-http-blade-adapter</artifactId>
42-
<version>1.0.3</version>
42+
<version>1.0.4</version>
4343
</dependency>
4444
```
4545
2. 使用适配器重新构造

jap-http-adapter/jap-http-jakarta-adapter/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'jap-http servlet interface jakarta adapter'
88

99
java {

jap-http-adapter/jap-http-javax-adapter/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'jap-http servlet interface javax adapter'
88

99
java {

jap-http/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'jap-http servlet interface'
88

99
java {

webdav-jakarta/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'AliyunDrive Webdav jakarta implement'
88

99
java {

webdav-javax/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'AliyunDrive Webdav javax implement'
88

99
java {

webdav/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.xdow'
6-
version '1.0.3'
6+
version '1.0.4'
77
description 'AliyunDrive Webdav core'
88

99
java {

0 commit comments

Comments
 (0)