Skip to content

Commit

Permalink
optimize: file client for api change.
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao committed Jun 30, 2023
1 parent 81ca94f commit 3e04579
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 32 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ ext {
}



dependencies {
compileOnly "org.springframework:spring-context:$springContext"
compileOnly "org.pf4j:pf4j:$pf4j"
compileOnly "io.projectreactor:reactor-core:3.5.1"
compileOnly "org.springframework:spring-webflux:6.0.3"
compileOnly "org.springdoc:springdoc-openapi-starter-webflux-api:2.0.2"

compileOnly files(libFile)
testImplementation files(libFile)

testImplementation "org.springframework:spring-context:$springContext"
testImplementation "org.pf4j:pf4j:$pf4j"
Expand All @@ -34,7 +35,7 @@ dependencies {
testImplementation "org.springdoc:springdoc-openapi-starter-webflux-api:2.0.2"
testImplementation 'org.slf4j:slf4j-api:2.0.7'
testImplementation 'org.slf4j:slf4j-simple:2.0.7'
testImplementation files(libFile)


// lombok
compileOnly "org.projectlombok:lombok:$lombok"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=run.ikaros.plugin.baidupan
description=a bai du pan plugin for ikaros.
version=0.1.1
version=0.1.2
Binary file modified lib/api-0.3.0-sources.jar
Binary file not shown.
Binary file modified lib/api-0.3.0.jar
Binary file not shown.
9 changes: 5 additions & 4 deletions src/main/java/run/ikaros/plugin/baidupan/BaiDuPanClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down Expand Up @@ -263,12 +264,12 @@ private void uploadChunkFile(File file, String path, String uploadId, int index)
}


public void download(List<String> fsIdList, Path targetDirPath) {
public void download(String fsId, Path targetDirPath) {
Assert.notNull(targetDirPath, "'targetDirPath' must not null.");
Assert.notNull(fsIdList, "'fsIdList' must not null.");
Assert.notNull(fsId, "'fsId' must not null.");

List<Long> list = fsIdList.stream().map(Long::valueOf).toList();
log.debug("fsids: {}", list);
List<Long> list = Stream.of(fsId).map(Long::valueOf).toList();
log.debug("fsids: {}", fsId);

// 获取文件信息和下载链接
UriComponents uriComponents =
Expand Down
42 changes: 19 additions & 23 deletions src/main/java/run/ikaros/plugin/baidupan/BaiDuPanFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.pf4j.Extension;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import run.ikaros.api.core.file.RemoteFileChunk;
import run.ikaros.api.core.file.RemoteFileHandler;
import run.ikaros.plugin.baidupan.result.FileCreateResult;
Expand All @@ -27,32 +28,27 @@ public String remote() {
}

@Override
public List<RemoteFileChunk> push(Path path) {
File[] files = path.toFile().listFiles();
if (files == null) {
throw new RuntimeException("has not files for path: " + path);
}
List<RemoteFileChunk> remoteFileChunks = new ArrayList<>();
for (File file : files) {
FileCreateResult fileCreateResult = client.uploadFile(file.toPath());
RemoteFileChunk remoteFileChunk = new RemoteFileChunk();
remoteFileChunk.setFileId(String.valueOf(fileCreateResult.getFsId()));
remoteFileChunk.setFileName(String.valueOf(fileCreateResult.getFilename()));
remoteFileChunk.setCategory(fileCreateResult.getCategory());
remoteFileChunk.setPath(fileCreateResult.getPath());
remoteFileChunk.setMd5(fileCreateResult.getMd5());
remoteFileChunk.setIsDir(fileCreateResult.getIsDir() == 1);
remoteFileChunk.setSize(fileCreateResult.getSize());
log.info("upload chunk file to remote[{}] for name: [{}].",
BaiDuPanConst.REMOTE, file.getName());
remoteFileChunks.add(remoteFileChunk);
}
return remoteFileChunks;
public RemoteFileChunk push(Path path) {
Assert.notNull(path, "'path' must not null.");
File file = path.toFile();
Assert.notNull(file, "'path file' must not null.");
FileCreateResult fileCreateResult = client.uploadFile(file.toPath());
RemoteFileChunk remoteFileChunk = new RemoteFileChunk();
remoteFileChunk.setFileId(String.valueOf(fileCreateResult.getFsId()));
remoteFileChunk.setFileName(String.valueOf(fileCreateResult.getFilename()));
remoteFileChunk.setCategory(fileCreateResult.getCategory());
remoteFileChunk.setPath(fileCreateResult.getPath());
remoteFileChunk.setMd5(fileCreateResult.getMd5());
remoteFileChunk.setIsDir(fileCreateResult.getIsDir() == 1);
remoteFileChunk.setSize(fileCreateResult.getSize());
log.info("upload chunk file to remote[{}] for name: [{}].",
BaiDuPanConst.REMOTE, file.getName());
return remoteFileChunk;
}

@Override
public void pull(Path targetDirPath, List<String> fsIdList) {
client.download(fsIdList, targetDirPath);
public void pull(Path targetDirPath, String fsId) {
client.download(fsId, targetDirPath);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: PluginBaiDuPan
# plugin entry class that extends BasePlugin
clazz: run.ikaros.plugin.baidupan.BaiDuPanPlugin
# plugin 'version' is a valid semantic version string (see semver.org).
version: 0.1.1
version: 0.1.2
requires: ">=0.3.0"
author:
name: Ikaros OSS Team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void download() {
configMap.putDataItem("refreshToken", System.getenv("TEST_REFRESH_TOKEN"));
baiDuPanClient.init(configMap);

baiDuPanClient.download(List.of("190341088047736"),
baiDuPanClient.download("190341088047736",
Path.of(new File("C:\\Develop\\test\\ikaros-plugin\\encrypt").toURI()));
}

Expand Down

0 comments on commit 3e04579

Please sign in to comment.