diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 856fcaa..9e2978b 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -2,6 +2,12 @@ 更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。 +# 0.12.2 + +## 优化 + +- alist路径支持直接复制浏览器的URL,而无需去特意复制相对路径。 + # 0.12.1 ## 新特性 diff --git a/console/src/views/AListControl.vue b/console/src/views/AListControl.vue index cd655bc..bb2be80 100644 --- a/console/src/views/AListControl.vue +++ b/console/src/views/AListControl.vue @@ -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 编码 diff --git a/gradle.properties b/gradle.properties index bc32c2c..5a77641 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=run.ikaros.plugin.alist description=A ikaros plugin for alist. -version=0.12.1 \ No newline at end of file +version=0.12.2 \ No newline at end of file diff --git a/src/main/java/run/ikaros/plugin/alist/AListEndpoint.java b/src/main/java/run/ikaros/plugin/alist/AListEndpoint.java index 2228d03..3219e9c 100644 --- a/src/main/java/run/ikaros/plugin/alist/AListEndpoint.java +++ b/src/main/java/run/ikaros/plugin/alist/AListEndpoint.java @@ -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; @@ -41,8 +37,8 @@ public AListEndpoint(AListClient aListClient) { @Override public RouterFunction 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") @@ -53,7 +49,7 @@ public RouterFunction endpoint() { .content(contentBuilder() .mediaType(MediaType.APPLICATION_JSON_VALUE)) .implementation(AListImportPostBody.class))) - .build(); + .build(); } Mono doImportFilesFromAList(ServerRequest request) { @@ -62,8 +58,10 @@ Mono 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) @@ -73,6 +71,22 @@ Mono doImportFilesFromAList(ServerRequest request) { .switchIfEmpty(ServerResponse.notFound().build()); } + /** + * 支持直接复制AList浏览器URL,而无需去区分是不是相对路径。 + * + * @param path 浏览器URL + * @return 相对路径 + */ + private Mono 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;