mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-13 13:18:58 +00:00
1、seetaface6兼容linux系统
2、支持设置全局缓存路径 3、优化部分功能
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>ink.numberone</groupId>
|
||||
<artifactId>smartjavaai-parent</artifactId>
|
||||
<version>1.0.8</version>
|
||||
<version>1.0.10</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>smartjavaai-common</artifactId>
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package cn.smartjavaai.common.config;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import cn.hutool.system.UserInfo;
|
||||
import cn.smartjavaai.common.utils.FileUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 全局配置
|
||||
* @author dwj
|
||||
* @date 2025/4/15
|
||||
*/
|
||||
@Slf4j
|
||||
public class Config {
|
||||
|
||||
/**
|
||||
* 默认缓存文件夹
|
||||
*/
|
||||
private static final String CACHE_DIR = "smartjavaai_cache";
|
||||
|
||||
private static String cachePath;
|
||||
|
||||
static{
|
||||
createCachePath();
|
||||
if(StringUtils.isNotBlank(cachePath)){
|
||||
System.setProperty("DJL_CACHE_DIR", cachePath);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置缓存路径的方法
|
||||
public static void setCachePath(String customeCachePath) {
|
||||
if (StringUtils.isNotBlank(customeCachePath)) {
|
||||
/*if(!FileUtils.isValidDirectory(customeCachePath)){
|
||||
throw new IllegalArgumentException("无效的缓存路径");
|
||||
}*/
|
||||
cachePath = customeCachePath;
|
||||
FileUtil.mkdir(cachePath);
|
||||
// 如果需要在此时直接设置系统属性
|
||||
System.setProperty("DJL_CACHE_DIR", cachePath);
|
||||
} else {
|
||||
throw new IllegalArgumentException("缓存路径不允许为空");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取缓存路径的方法
|
||||
public static String getCachePath() {
|
||||
if(StringUtils.isBlank(cachePath)){
|
||||
createCachePath();
|
||||
}
|
||||
if(StringUtils.isNotBlank(cachePath)){
|
||||
System.setProperty("DJL_CACHE_DIR", cachePath);
|
||||
}
|
||||
return cachePath;
|
||||
}
|
||||
|
||||
// 获取当前缓存路径的系统属性(如果需要在其他地方使用)
|
||||
public static String getCachePathFromSystem() {
|
||||
return System.getProperty("DJL_CACHE_DIR");
|
||||
}
|
||||
|
||||
private static void createCachePath(){
|
||||
String osName = SystemUtil.getOsInfo().getName();
|
||||
log.info("当前操作系统:{}", osName);
|
||||
if(osName.toLowerCase().contains("windows")){
|
||||
cachePath = SystemUtil.getUserInfo().getHomeDir() + CACHE_DIR;
|
||||
FileUtil.mkdir(cachePath);
|
||||
}else if(osName.toLowerCase().contains("linux")){
|
||||
cachePath = "/root/" + CACHE_DIR;
|
||||
FileUtil.mkdir(cachePath);
|
||||
}else if(osName.toLowerCase().contains("mac")){
|
||||
cachePath = SystemUtil.getUserInfo().getHomeDir() + CACHE_DIR;
|
||||
FileUtil.mkdir(cachePath);
|
||||
}else{
|
||||
cachePath = SystemUtil.getUserInfo().getHomeDir() + CACHE_DIR;
|
||||
FileUtil.mkdir(cachePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,4 +18,14 @@ public class FileUtils {
|
||||
File file = new File(filePath);
|
||||
return file.exists() && !file.isDirectory(); // 确保是文件且存在
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查目录是否存在
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidDirectory(String path) {
|
||||
File file = new File(path);
|
||||
return file.exists() && file.isDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user