Skip to content

Commit

Permalink
feat: 支持直接复制AList浏览器路径而不是相对路径进行导入。
Browse files Browse the repository at this point in the history
  • Loading branch information
li-guohao committed Jun 10, 2024
1 parent 9c4010b commit db0811d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

# 0.12.2

## 优化

- alist路径支持直接复制浏览器的URL,而无需去特意复制相对路径。

# 0.12.1

## 新特性
Expand Down
2 changes: 1 addition & 1 deletion console/src/views/AListControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const http = axios.create({
const doPostImportPath = () => {
if (!path.value) {
window.alert('请输入alist的相对路径,比如:/PKPK/LP-Raws/');
window.alert('请输入alist的浏览器路径,比如:https://domain.com/PKPK/LP-Raws');
return;
}
// basic64 编码
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.alist
description=A ikaros plugin for alist.
version=0.12.1
version=0.12.2
32 changes: 23 additions & 9 deletions src/main/java/run/ikaros/plugin/alist/AListEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,23 @@
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import run.ikaros.api.custom.GroupVersionKind;
import run.ikaros.api.custom.ReactiveCustomClient;
import run.ikaros.api.endpoint.CustomEndpoint;
import run.ikaros.api.infra.utils.StringUtils;

import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.Objects;

import static org.springdoc.core.fn.builders.content.Builder.contentBuilder;
import static org.springdoc.core.fn.builders.encoding.Builder.encodingBuilder;
import static org.springdoc.core.fn.builders.schema.Builder.schemaBuilder;

@Slf4j
@Component
public class AListEndpoint implements CustomEndpoint {

private GroupVersionKind groupVersionKind =
new GroupVersionKind("plugin.ikaros.run", "v1alpha1", AListPlugin.NAME);
new GroupVersionKind("plugin.ikaros.run", "v1alpha1", AListPlugin.NAME);

private final AListClient aListClient;

Expand All @@ -41,8 +37,8 @@ public AListEndpoint(AListClient aListClient) {
@Override
public RouterFunction<ServerResponse> endpoint() {
var tag = groupVersionKind.group()
+ "/" + groupVersionKind.version()
+ "/" + groupVersionKind.kind();
+ "/" + groupVersionKind.version()
+ "/" + groupVersionKind.kind();
return SpringdocRouteBuilder.route()
.POST("/alist/import", this::doImportFilesFromAList,
builder -> builder.operationId("ImportAlistFiles")
Expand All @@ -53,7 +49,7 @@ public RouterFunction<ServerResponse> endpoint() {
.content(contentBuilder()
.mediaType(MediaType.APPLICATION_JSON_VALUE))
.implementation(AListImportPostBody.class)))
.build();
.build();
}

Mono<ServerResponse> doImportFilesFromAList(ServerRequest request) {
Expand All @@ -62,8 +58,10 @@ Mono<ServerResponse> doImportFilesFromAList(ServerRequest request) {
.map(AListImportPostBody::getPath)
.map(path -> new String(Base64.getDecoder().decode(path), StandardCharsets.UTF_8))
.map(path -> URLDecoder.decode(path, StandardCharsets.UTF_8))
.doOnSuccess(s -> log.debug("paths: {}", s))
.doOnSuccess(s -> log.debug("path: {}", s))
.filter(StringUtils::isNotBlank)
.flatMap(this::removeHttpPrefixIfExists)
.doOnSuccess(s -> log.debug("relative path: {}", s))
.map(path -> Arrays.stream(path.split("/")).filter(StringUtils::isNotBlank).toList())
.doOnSuccess(strings -> log.debug("strings size: {}", strings.size()))
.filter(Objects::nonNull)
Expand All @@ -73,6 +71,22 @@ Mono<ServerResponse> doImportFilesFromAList(ServerRequest request) {
.switchIfEmpty(ServerResponse.notFound().build());
}

/**
* 支持直接复制AList浏览器URL,而无需去区分是不是相对路径。
*
* @param path 浏览器URL
* @return 相对路径
*/
private Mono<String> removeHttpPrefixIfExists(String path) {
if (path.startsWith("http://") || path.startsWith("https://")) {
return aListClient.getToken()
.map(AListToken::getUrl)
.map(url -> path.replace(url, ""))
.map(p -> p.startsWith("/") ? p : "/" + p);
}
return Mono.just(path);
}

@Override
public GroupVersionKind groupVersionKind() {
return groupVersionKind;
Expand Down

0 comments on commit db0811d

Please sign in to comment.