fix(file): 修复本地文件上传助手的路径配置问题
- 添加了对操作系统名称为空的兜底处理,默认使用Linux路径 - 修复了Mac系统路径中用户名占位符的配置,添加当前用户名获取功能 - 引入KitSystemUtil工具类的getCurrentUserName方法获取系统用户名 - 使用StrUtil工具类处理用户名为空的情况 - 在前端home页面添加系统API文档链接显示功能
This commit is contained in:
+16
-7
@@ -13,10 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.odboy.framework.server.core;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.util.KitSystemUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -32,17 +33,25 @@ public class KitFileLocalUploadHelper {
|
||||
*/
|
||||
private static final int AVATAR_MAX_SIZE = 5;
|
||||
private static final String PATH_WINDOWS = "C:\\${appName}\\file\\";
|
||||
private static final String PATH_MAC = "/Users/odboy/${appName}/file/";
|
||||
private static final String PATH_MAC = "/Users${username}/${appName}/file/";
|
||||
private static final String PATH_LINUX = "/home/${appName}/file/";
|
||||
@Value("${spring.application.name}")
|
||||
private String appName;
|
||||
@Value("${spring.application.name}") private String appName;
|
||||
|
||||
public String getPath() {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.toLowerCase().startsWith(SystemConst.WIN)) {
|
||||
if (os == null) {
|
||||
// 默认使用 Linux 路径作为兜底方案
|
||||
return PATH_LINUX.replace("${appName}", appName);
|
||||
}
|
||||
String lowerOs = os.toLowerCase();
|
||||
if (lowerOs.startsWith(SystemConst.WIN)) {
|
||||
return PATH_WINDOWS.replace("${appName}", appName);
|
||||
} else if (os.toLowerCase().startsWith(SystemConst.MAC)) {
|
||||
return PATH_MAC.replace("${appName}", appName);
|
||||
} else if (lowerOs.startsWith(SystemConst.MAC)) {
|
||||
String currentUserName = KitSystemUtil.getCurrentUserName();
|
||||
if (StrUtil.isBlank(currentUserName)) {
|
||||
return PATH_MAC.replace("${appName}", appName).replace("${username}", "");
|
||||
}
|
||||
return PATH_MAC.replace("${appName}", appName).replace("${username}", currentUserName);
|
||||
}
|
||||
return PATH_LINUX.replace("${appName}", appName);
|
||||
}
|
||||
|
||||
@@ -32,4 +32,11 @@ public class KitSystemUtil {
|
||||
CentralProcessor processor = systemInfo.getHardware().getProcessor();
|
||||
return processor.getPhysicalProcessorCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前系统的用户名
|
||||
*/
|
||||
public static String getCurrentUserName() {
|
||||
return System.getProperty("user.name");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user