mirror of
https://github.com/dataease/dataease.git
synced 2026-05-19 10:18:11 +08:00
chore: 将资源的固定路径优化为可读取yml配置中的路径
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package io.dataease.constant;
|
||||
|
||||
import io.dataease.utils.ConfigUtils;
|
||||
import io.dataease.utils.ModelUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static io.dataease.utils.StaticResourceUtils.ensureSuffix;
|
||||
@@ -11,7 +14,7 @@ public class StaticResourceConstants {
|
||||
|
||||
public static final String FILE_SEPARATOR = File.separator;
|
||||
|
||||
public static final String USER_HOME = "/opt/dataease2.0/data";
|
||||
public static final String USER_HOME = getHomeData();
|
||||
|
||||
public static String WORK_DIR = ensureSuffix(USER_HOME, FILE_SEPARATOR) + "static-resource" + FILE_SEPARATOR;
|
||||
|
||||
@@ -36,4 +39,11 @@ public class StaticResourceConstants {
|
||||
*/
|
||||
public static final String URL_SEPARATOR = "/";
|
||||
|
||||
public static String getHomeData() {
|
||||
if (ModelUtils.isDesktop()) {
|
||||
return ConfigUtils.getConfig("dataease.path.data", "/opt/dataease2.0/data");
|
||||
} else {
|
||||
return "/opt/dataease2.0/data";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
sdk/common/src/main/java/io/dataease/utils/ConfigUtils.java
Normal file
29
sdk/common/src/main/java/io/dataease/utils/ConfigUtils.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package io.dataease.utils;
|
||||
|
||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author Junjun
|
||||
*/
|
||||
public class ConfigUtils {
|
||||
|
||||
public static String getConfig(String key, String defaultValue) {
|
||||
try {
|
||||
String filePath = System.getProperty("user.dir");
|
||||
filePath = filePath.replace("file:", "").substring(0, filePath.lastIndexOf("resources"));
|
||||
Resource resource = new FileSystemResource(filePath + "resources" + File.separator + "config" + File.separator + "application.yml");
|
||||
// Resource resource = new FileSystemResource("D:\\dataease\\electron\\dataease-desktop\\resources\\config\\application.yml");
|
||||
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
|
||||
factory.setResources(resource);
|
||||
String property = Objects.requireNonNull(factory.getObject()).getProperty(key, defaultValue);
|
||||
return property.replaceAll("\\$\\{user.home}", System.getProperty("user.home").replaceAll("\\\\", "/"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user