fix(file): 修复本地文件上传助手的路径配置问题
- 添加了对操作系统名称为空的兜底处理,默认使用Linux路径 - 修复了Mac系统路径中用户名占位符的配置,添加当前用户名获取功能 - 引入KitSystemUtil工具类的getCurrentUserName方法获取系统用户名 - 使用StrUtil工具类处理用户名为空的情况 - 在前端home页面添加系统API文档链接显示功能
This commit is contained in:
@@ -3,6 +3,10 @@
|
|||||||
<div class="dashboard-editor-container">
|
<div class="dashboard-editor-container">
|
||||||
<github-corner class="github-corner" />
|
<github-corner class="github-corner" />
|
||||||
|
|
||||||
|
<el-row :gutter="40" style="background-color: white;margin-left: 2px;margin-right: 2px;padding: 6px">
|
||||||
|
<el-col>系统API文档:<el-link type="primary" :href="swaggerApi" target="_blank">{{ swaggerApi }}</el-link></el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
<panel-group @handleSetLineChartData="handleSetLineChartData" />
|
<panel-group @handleSetLineChartData="handleSetLineChartData" />
|
||||||
|
|
||||||
<el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
|
<el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
|
||||||
@@ -36,6 +40,7 @@ import LineChart from './dashboard/LineChart'
|
|||||||
import RadarChart from '@/components/Echarts/RadarChart'
|
import RadarChart from '@/components/Echarts/RadarChart'
|
||||||
import PieChart from '@/components/Echarts/PieChart'
|
import PieChart from '@/components/Echarts/PieChart'
|
||||||
import BarChart from '@/components/Echarts/BarChart'
|
import BarChart from '@/components/Echarts/BarChart'
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
const lineChartData = {
|
const lineChartData = {
|
||||||
newVisitis: {
|
newVisitis: {
|
||||||
@@ -68,6 +73,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
swaggerApi: store.getters.swaggerApi,
|
||||||
lineChartData: lineChartData.newVisitis
|
lineChartData: lineChartData.newVisitis
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+16
-7
@@ -13,10 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cn.odboy.framework.server.core;
|
package cn.odboy.framework.server.core;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.constant.SystemConst;
|
import cn.odboy.constant.SystemConst;
|
||||||
|
import cn.odboy.util.KitSystemUtil;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -32,17 +33,25 @@ public class KitFileLocalUploadHelper {
|
|||||||
*/
|
*/
|
||||||
private static final int AVATAR_MAX_SIZE = 5;
|
private static final int AVATAR_MAX_SIZE = 5;
|
||||||
private static final String PATH_WINDOWS = "C:\\${appName}\\file\\";
|
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/";
|
private static final String PATH_LINUX = "/home/${appName}/file/";
|
||||||
@Value("${spring.application.name}")
|
@Value("${spring.application.name}") private String appName;
|
||||||
private String appName;
|
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
String os = System.getProperty("os.name");
|
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);
|
return PATH_WINDOWS.replace("${appName}", appName);
|
||||||
} else if (os.toLowerCase().startsWith(SystemConst.MAC)) {
|
} else if (lowerOs.startsWith(SystemConst.MAC)) {
|
||||||
return PATH_MAC.replace("${appName}", appName);
|
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);
|
return PATH_LINUX.replace("${appName}", appName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,4 +32,11 @@ public class KitSystemUtil {
|
|||||||
CentralProcessor processor = systemInfo.getHardware().getProcessor();
|
CentralProcessor processor = systemInfo.getHardware().getProcessor();
|
||||||
return processor.getPhysicalProcessorCount();
|
return processor.getPhysicalProcessorCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前系统的用户名
|
||||||
|
*/
|
||||||
|
public static String getCurrentUserName() {
|
||||||
|
return System.getProperty("user.name");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-4
@@ -15,7 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package cn.odboy.framework.server.core;
|
package cn.odboy.framework.server.core;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.constant.SystemConst;
|
import cn.odboy.constant.SystemConst;
|
||||||
|
import cn.odboy.util.KitSystemUtil;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -31,16 +33,25 @@ public class KitFileLocalUploadHelper {
|
|||||||
*/
|
*/
|
||||||
private static final int AVATAR_MAX_SIZE = 5;
|
private static final int AVATAR_MAX_SIZE = 5;
|
||||||
private static final String PATH_WINDOWS = "C:\\${appName}\\file\\";
|
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/";
|
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() {
|
public String getPath() {
|
||||||
String os = System.getProperty("os.name");
|
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);
|
return PATH_WINDOWS.replace("${appName}", appName);
|
||||||
} else if (os.toLowerCase().startsWith(SystemConst.MAC)) {
|
} else if (lowerOs.startsWith(SystemConst.MAC)) {
|
||||||
return PATH_MAC.replace("${appName}", appName);
|
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);
|
return PATH_LINUX.replace("${appName}", appName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,4 +30,11 @@ public class KitSystemUtil {
|
|||||||
CentralProcessor processor = systemInfo.getHardware().getProcessor();
|
CentralProcessor processor = systemInfo.getHardware().getProcessor();
|
||||||
return processor.getPhysicalProcessorCount();
|
return processor.getPhysicalProcessorCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前系统的用户名
|
||||||
|
*/
|
||||||
|
public static String getCurrentUserName() {
|
||||||
|
return System.getProperty("user.name");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user