Skip to content

Commit e491370

Browse files
author
li-guohao
committed
optimize: 启动时自动加载alist的token
1 parent f393db0 commit e491370

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

CHANGELOG.MD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。
44

5+
# 0.12.7
6+
7+
## 优化
8+
9+
- 启动时自动加载alist的token
10+
511
# 0.12.6
612

713
## 优化

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group=run.ikaros.plugin.alist
22
description=A ikaros plugin for alist.
3-
version=0.12.6
3+
version=0.12.7

src/main/java/run/ikaros/plugin/alist/AListClient.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.core.type.TypeReference;
44
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.beans.factory.DisposableBean;
6+
import org.springframework.beans.factory.InitializingBean;
57
import org.springframework.boot.context.event.ApplicationReadyEvent;
68
import org.springframework.context.event.EventListener;
79
import org.springframework.http.HttpEntity;
@@ -31,7 +33,7 @@
3133

3234
@Slf4j
3335
@Component
34-
public class AListClient {
36+
public class AListClient implements InitializingBean, DisposableBean {
3537
private final RestTemplate restTemplate = new RestTemplate();
3638
private HttpHeaders httpHeaders = new HttpHeaders();
3739
private AListToken token;
@@ -92,7 +94,8 @@ private Mono<Void> createAttachmentRecursively(List<String> paths, Long parentId
9294
.flatMap(aListAttachment -> {
9395
if (aListAttachment.getIs_dir()) {
9496
List<String> paths1 = aListAttachment.getPaths();
95-
return createAttachmentRecursively(paths1, aListAttachment.getId());
97+
return createAttachmentRecursively(paths1, aListAttachment.getId())
98+
.subscribeOn(Schedulers.boundedElastic());
9699
} else {
97100
return Mono.empty();
98101
}
@@ -205,6 +208,7 @@ public Mono<AListToken> refreshToken(boolean refresh) {
205208
Object token1 = apiResult.getData().get("token");
206209
httpHeaders.set("Authorization", String.valueOf(token1));
207210
token.setToken(String.valueOf(token1));
211+
log.info("refresh alist token success");
208212
return customClient.update(token2cm(token))
209213
.then(Mono.just(token));
210214
} else {
@@ -340,14 +344,20 @@ public Mono<AListToken> updateOperateByToken() {
340344
return getToken().flatMap(aListToken -> refreshToken(true));
341345
}
342346

343-
@EventListener(ApplicationReadyEvent.class)
344-
public Mono<Void> initAListToken() {
345-
log.debug("init alist token.");
346-
if (Objects.isNull(token)) {
347+
@Override
348+
public void destroy() throws Exception {
349+
if (Objects.nonNull(refreshTokenTaskDisposable) && !refreshTokenTaskDisposable.isDisposed()) {
350+
refreshTokenTaskDisposable.dispose();
351+
}
352+
}
353+
354+
@Override
355+
public void afterPropertiesSet() throws Exception {
356+
log.debug("init alist token afterPropertiesSet.");
357+
if (Objects.isNull(token) || StringUtils.isBlank(token.getToken())) {
347358
// token is null, get config from db.
348-
return updateOperateByToken().then();
359+
updateOperateByToken().subscribe();
349360
}
350-
return Mono.empty();
351361
}
352362

353363

src/main/resources/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: PluginAList
44
# plugin entry class that extends BasePlugin
55
clazz: run.ikaros.plugin.alist.AListPlugin
66
# plugin 'version' is a valid semantic version string (see semver.org).
7-
version: 0.12.6
7+
version: 0.12.7
88
requires: ">=0.12.1"
99
author:
1010
name: Ikaros OSS Team

0 commit comments

Comments
 (0)