|
|
@@ -2,8 +2,8 @@ package com.zsjz.ai.module.plugin.controller;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.zsjz.ai.common.constants.PathConst;
|
|
|
import com.zsjz.ai.common.exception.ServerException;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
import org.springframework.http.CacheControl;
|
|
|
@@ -19,7 +19,6 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
-import java.nio.file.Paths;
|
|
|
import java.time.Duration;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
@@ -30,9 +29,9 @@ import java.util.regex.Pattern;
|
|
|
* 本机插件市场:目录、插件包和安装解析接口。
|
|
|
*
|
|
|
* <p>桌面端 host-core 以匿名 HTTP 直接读取这三个接口,不走登录态,因此
|
|
|
- * {@code /plugin/**} 必须加入 Sa-Token 白名单。目录与包位于
|
|
|
- * {@code plugin.market.root-path} 下:{@code catalog.json} 与
|
|
|
- * {@code packages/*.piplug}。
|
|
|
+ * {@code /plugin/**} 必须加入 Sa-Token 白名单。目录与包属于系统资产,路径由
|
|
|
+ * {@link PathConst#PLUGIN_MARKET_PATH} 维护:{@code qingjian/system/plugin-market}
|
|
|
+ * 下的 {@code catalog.json} 与 {@code packages/*.piplug}。
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/plugin")
|
|
|
@@ -42,13 +41,9 @@ public class PluginMarketController {
|
|
|
private static final Pattern PACKAGE_NAME =
|
|
|
Pattern.compile("^[A-Za-z0-9][A-Za-z0-9._-]*\\.piplug$");
|
|
|
|
|
|
- private final Path marketRoot;
|
|
|
private final ObjectMapper objectMapper;
|
|
|
|
|
|
- public PluginMarketController(
|
|
|
- @Value("${plugin.market.root-path:./data/plugin-market}") String rootPath,
|
|
|
- ObjectMapper objectMapper) {
|
|
|
- this.marketRoot = Paths.get(rootPath).toAbsolutePath().normalize();
|
|
|
+ public PluginMarketController(ObjectMapper objectMapper) {
|
|
|
this.objectMapper = objectMapper;
|
|
|
}
|
|
|
|
|
|
@@ -71,7 +66,7 @@ public class PluginMarketController {
|
|
|
if (!PACKAGE_NAME.matcher(filename).matches()) {
|
|
|
throw new ServerException(400, "非法的插件包文件名");
|
|
|
}
|
|
|
- Path packagesRoot = marketRoot.resolve("packages").normalize();
|
|
|
+ Path packagesRoot = PathConst.PLUGIN_MARKET_PACKAGES_PATH.toAbsolutePath().normalize();
|
|
|
Path file = packagesRoot.resolve(filename).normalize();
|
|
|
if (!file.startsWith(packagesRoot) || !Files.isRegularFile(file)) {
|
|
|
throw new ServerException(404, "插件包不存在");
|
|
|
@@ -130,7 +125,7 @@ public class PluginMarketController {
|
|
|
}
|
|
|
|
|
|
private Path catalogPath() {
|
|
|
- return marketRoot.resolve("catalog.json").normalize();
|
|
|
+ return PathConst.PLUGIN_MARKET_CATALOG_PATH.toAbsolutePath().normalize();
|
|
|
}
|
|
|
|
|
|
private static JsonNode findVersion(JsonNode catalog, String pluginId, String version) {
|