diff --git a/src/main/java/cn/somkit/fmt/action/DownloadAction.java b/src/main/java/cn/somkit/fmt/action/DownloadAction.java index c685809..f27ff78 100644 --- a/src/main/java/cn/somkit/fmt/action/DownloadAction.java +++ b/src/main/java/cn/somkit/fmt/action/DownloadAction.java @@ -4,6 +4,7 @@ import cn.somkit.fmt.annotation.ApiOperate; import cn.somkit.fmt.config.FmtConfig; import cn.somkit.fmt.config.RocksDBConfig; import cn.somkit.fmt.utils.MD5Utils; +import cn.somkit.fmt.utils.ParamUtils; import cn.somkit.fmt.utils.PathUtils; import cn.somkit.fmt.utils.RocksDBUtils; import jakarta.servlet.http.HttpServletResponse; @@ -31,10 +32,9 @@ import java.util.zip.ZipOutputStream; public class DownloadAction { @GetMapping("/index") - @ApiOperate(description = "下载页面跳转") public ModelAndView index(String keyboard) throws Exception{ - PathUtils.directory(FmtConfig.Upload_File_Path); - File folder = new File(FmtConfig.Upload_File_Path); + PathUtils.directory(ParamUtils.getUploadPath()); + File folder = new File(ParamUtils.getUploadPath()); File[] listOfFiles = folder.listFiles(); List> list = new ArrayList<>(); List keys = RocksDBUtils.getAllKey(RocksDBConfig.RocksDB_Column_Family); @@ -124,12 +124,12 @@ public class DownloadAction { @ApiOperate(description = "批量文件打包下载") public Map packZip(String filenames) throws Exception{ try { - PathUtils.directory(FmtConfig.Upload_File_Path); - PathUtils.directory(FmtConfig.Temp_File_Path); + PathUtils.directory(ParamUtils.getUploadPath()); + PathUtils.directory(ParamUtils.getTempFilePath()); String zipName = String.valueOf(System.currentTimeMillis()); - String zipDir = FmtConfig.Temp_File_Path + File.separator + zipName + ".zip"; + String zipDir = ParamUtils.getTempFilePath() + File.separator + zipName + ".zip"; ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipDir)); - File folder = new File(FmtConfig.Upload_File_Path); + File folder = new File(ParamUtils.getUploadPath()); File[] listOfFiles = folder.listFiles(); assert listOfFiles != null; for (File file : listOfFiles) { @@ -171,8 +171,8 @@ public class DownloadAction { @ResponseBody @ApiOperate(description = "批量文件删除") public String batchDel(String filenames) throws Exception{ - PathUtils.directory(FmtConfig.Upload_File_Path); - File folder = new File(FmtConfig.Upload_File_Path); + PathUtils.directory(ParamUtils.getUploadPath()); + File folder = new File(ParamUtils.getUploadPath()); File[] listOfFiles = folder.listFiles(); assert listOfFiles != null; for (File file : listOfFiles) { diff --git a/src/main/java/cn/somkit/fmt/action/IndexAction.java b/src/main/java/cn/somkit/fmt/action/IndexAction.java index 939121b..9d7a52a 100644 --- a/src/main/java/cn/somkit/fmt/action/IndexAction.java +++ b/src/main/java/cn/somkit/fmt/action/IndexAction.java @@ -9,7 +9,6 @@ import org.springframework.web.servlet.ModelAndView; public class IndexAction { @RequestMapping("/") - @ApiOperate(description = "默认跳转") public ModelAndView index(){ return new ModelAndView("redirect:/download/index"); } diff --git a/src/main/java/cn/somkit/fmt/action/LoggingAction.java b/src/main/java/cn/somkit/fmt/action/LoggingAction.java index 98fcdef..41f2720 100644 --- a/src/main/java/cn/somkit/fmt/action/LoggingAction.java +++ b/src/main/java/cn/somkit/fmt/action/LoggingAction.java @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.RequestMapping; public class LoggingAction { @GetMapping("/index") - @ApiOperate(description = "在线日志页面跳转") public String index() throws Exception{ return "logging"; } diff --git a/src/main/java/cn/somkit/fmt/action/SystemAction.java b/src/main/java/cn/somkit/fmt/action/SystemAction.java new file mode 100644 index 0000000..2a17172 --- /dev/null +++ b/src/main/java/cn/somkit/fmt/action/SystemAction.java @@ -0,0 +1,53 @@ +package cn.somkit.fmt.action; + +import cn.somkit.fmt.annotation.ApiOperate; +import cn.somkit.fmt.config.FmtConfig; +import cn.somkit.fmt.utils.ParamUtils; +import cn.somkit.fmt.utils.PathUtils; +import cn.somkit.fmt.utils.RocksDBUtils; +import org.rocksdb.RocksDBException; +import org.springframework.stereotype.Controller; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping("/system") +public class SystemAction { + + @GetMapping("/index") + public ModelAndView index() throws Exception{ + Map map = new HashMap<>(); + map.put("Upload_File_Path", ParamUtils.getUploadPath()); + map.put("Temp_File_Path", ParamUtils.getTempFilePath()); + map.put("Log_File_Path", ParamUtils.getLogFilePath()); + map.put("Max_Read_Length", ParamUtils.getMaxReadLength()); + map.put("Read_Interval", ParamUtils.getReadInterval()); + ModelAndView mv = new ModelAndView(); + mv.setViewName("system"); + mv.addObject(FmtConfig.System_Cf_Name, map); + return mv; + } + + @PostMapping("/save") + @ResponseBody + @ApiOperate(description = "保存系统设置") + public Map save(@RequestParam Map map) throws Exception { + if(map != null && !map.isEmpty()){ + map.keySet().forEach(key -> { + try { + if(StringUtils.hasText(map.get(key))){ + String value = map.get(key).startsWith("./") ? PathUtils.resolve(map.get(key)) : map.get(key); + RocksDBUtils.put(FmtConfig.System_Cf_Name, key, value); + } + } catch (RocksDBException e) { + throw new RuntimeException(e); + } + }); + } + return Map.of("code", 200, "message", "保存成功"); + } +} diff --git a/src/main/java/cn/somkit/fmt/action/UploadAction.java b/src/main/java/cn/somkit/fmt/action/UploadAction.java index c7a1c0c..82daca4 100644 --- a/src/main/java/cn/somkit/fmt/action/UploadAction.java +++ b/src/main/java/cn/somkit/fmt/action/UploadAction.java @@ -4,6 +4,7 @@ import cn.somkit.fmt.annotation.ApiOperate; import cn.somkit.fmt.config.FmtConfig; import cn.somkit.fmt.config.RocksDBConfig; import cn.somkit.fmt.utils.MD5Utils; +import cn.somkit.fmt.utils.ParamUtils; import cn.somkit.fmt.utils.PathUtils; import cn.somkit.fmt.utils.RocksDBUtils; import jakarta.servlet.http.HttpServletRequest; @@ -24,7 +25,6 @@ import java.util.*; public class UploadAction { @GetMapping("/index") - @ApiOperate(description = "上传页面跳转") public String index() throws Exception{ return "upload"; } @@ -35,7 +35,7 @@ public class UploadAction { public Map execute(HttpServletRequest request) throws Exception{ //多个文件上传 就只是简单的多文件上传保存在本地的磁盘 if (request instanceof MultipartHttpServletRequest mrequest) { - PathUtils.directory(FmtConfig.Upload_File_Path); + PathUtils.directory(ParamUtils.getUploadPath()); List files = mrequest.getFiles("file"); // 取出每一个上传文件 for (MultipartFile file : files) { @@ -64,7 +64,7 @@ public class UploadAction { if(StringUtils.hasText(fileName)){ String hash = MD5Utils.md5HashCode(file.getInputStream()); RocksDBUtils.put(RocksDBConfig.RocksDB_Column_Family, fileName, hash); - filePath = FmtConfig.Upload_File_Path + File.separator + fileName; + filePath = ParamUtils.getUploadPath() + File.separator + fileName; File saveFile = new File(filePath) ; file.transferTo(saveFile); // 文件保存 } diff --git a/src/main/java/cn/somkit/fmt/config/LogSocketConfig.java b/src/main/java/cn/somkit/fmt/config/LogSocketConfig.java index a642174..b5a5d88 100644 --- a/src/main/java/cn/somkit/fmt/config/LogSocketConfig.java +++ b/src/main/java/cn/somkit/fmt/config/LogSocketConfig.java @@ -1,5 +1,6 @@ package cn.somkit.fmt.config; +import cn.somkit.fmt.utils.PathUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -16,6 +17,10 @@ public class LogSocketConfig { @Value("${somkit.logging.socket.log-file-path}") public void setLog_File_Path(String log_File_Path) { if(StringUtils.hasText(log_File_Path)){ + //如果使用相对路径,转换为绝对路径 + if(log_File_Path.startsWith("./")){ + log_File_Path = PathUtils.resolve(log_File_Path); + } Log_File_Path = log_File_Path; } } diff --git a/src/main/java/cn/somkit/fmt/config/RocksDBConfig.java b/src/main/java/cn/somkit/fmt/config/RocksDBConfig.java index a14fba8..56df54b 100644 --- a/src/main/java/cn/somkit/fmt/config/RocksDBConfig.java +++ b/src/main/java/cn/somkit/fmt/config/RocksDBConfig.java @@ -1,5 +1,6 @@ package cn.somkit.fmt.config; +import cn.somkit.fmt.utils.PathUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -14,6 +15,10 @@ public class RocksDBConfig { @Value("${somkit.cache.rocks-db.path}") public void setRocksDB_Path(String rocksDB_Path) { if(StringUtils.hasText(rocksDB_Path)){ + //如果使用相对路径,转换为绝对路径 + if(rocksDB_Path.startsWith("./")){ + rocksDB_Path = PathUtils.resolve(rocksDB_Path); + } RocksDB_Path = rocksDB_Path; } } diff --git a/src/main/java/cn/somkit/fmt/utils/LogSocketUtils.java b/src/main/java/cn/somkit/fmt/utils/LogSocketUtils.java index f6958b9..7a1c64f 100644 --- a/src/main/java/cn/somkit/fmt/utils/LogSocketUtils.java +++ b/src/main/java/cn/somkit/fmt/utils/LogSocketUtils.java @@ -27,7 +27,7 @@ public class LogSocketUtils { BufferedReader reader = null; try { //日志文件路径 - String filePath = LogSocketConfig.Log_File_Path; + String filePath = ParamUtils.getLogFilePath(); //字符流 reader = new BufferedReader(new FileReader(filePath)); Object[] lines = reader.lines().toArray(); @@ -61,7 +61,7 @@ public class LogSocketUtils { WebSocketOnline.logLengthMap.put(socketSessionId, lines.length); //第一次如果太大,截取最新的200行就够了,避免传输的数据太大 - int maxLength = Integer.parseInt(LogSocketConfig.Max_Read_Length); + int maxLength = Integer.parseInt(ParamUtils.getMaxReadLength()); if(first && copyOfRange.length > maxLength){ copyOfRange = Arrays.copyOfRange(copyOfRange, copyOfRange.length - maxLength, copyOfRange.length); first = false; @@ -74,7 +74,7 @@ public class LogSocketUtils { WebSocketOnline.sendMessage(socketSessionId, JSONUtil.toJsonStr(entity)); //休眠一秒 - Thread.sleep(Long.parseLong(LogSocketConfig.Read_Interval)); + Thread.sleep(Long.parseLong(ParamUtils.getReadInterval())); } catch (Exception e) { logger.error("读取日志异常:{}", ErrorUtil.errorInfoToString(e)); } finally { diff --git a/src/main/java/cn/somkit/fmt/utils/ParamUtils.java b/src/main/java/cn/somkit/fmt/utils/ParamUtils.java new file mode 100644 index 0000000..1837c74 --- /dev/null +++ b/src/main/java/cn/somkit/fmt/utils/ParamUtils.java @@ -0,0 +1,63 @@ +package cn.somkit.fmt.utils; + +import cn.somkit.fmt.config.FmtConfig; +import cn.somkit.fmt.config.LogSocketConfig; +import org.springframework.util.StringUtils; + +public class ParamUtils { + + public static String getUploadPath() throws Exception { + String path = RocksDBUtils.get(FmtConfig.System_Cf_Name, "Upload_File_Path"); + if(StringUtils.hasText(path)){ + return path; + } else { + path = FmtConfig.Upload_File_Path; + RocksDBUtils.put(FmtConfig.System_Cf_Name, "Upload_File_Path", path); + return path; + } + } + + public static String getTempFilePath() throws Exception { + String path = RocksDBUtils.get(FmtConfig.System_Cf_Name, "Temp_File_Path"); + if(StringUtils.hasText(path)){ + return path; + } else { + path = FmtConfig.Temp_File_Path; + RocksDBUtils.put(FmtConfig.System_Cf_Name, "Temp_File_Path", path); + return path; + } + } + + public static String getLogFilePath() throws Exception { + String path = RocksDBUtils.get(FmtConfig.System_Cf_Name, "Log_File_Path"); + if(StringUtils.hasText(path)){ + return path; + } else { + path = LogSocketConfig.Log_File_Path; + RocksDBUtils.put(FmtConfig.System_Cf_Name, "Log_File_Path", path); + return path; + } + } + + public static String getMaxReadLength() throws Exception { + String path = RocksDBUtils.get(FmtConfig.System_Cf_Name, "Max_Read_Length"); + if(StringUtils.hasText(path)){ + return path; + } else { + path = LogSocketConfig.Max_Read_Length; + RocksDBUtils.put(FmtConfig.System_Cf_Name, "Max_Read_Length", path); + return path; + } + } + + public static String getReadInterval() throws Exception { + String path = RocksDBUtils.get(FmtConfig.System_Cf_Name, "Read_Interval"); + if(StringUtils.hasText(path)){ + return path; + } else { + path = LogSocketConfig.Read_Interval; + RocksDBUtils.put(FmtConfig.System_Cf_Name, "Read_Interval", path); + return path; + } + } +} diff --git a/src/main/java/cn/somkit/fmt/utils/RocksDBUtils.java b/src/main/java/cn/somkit/fmt/utils/RocksDBUtils.java index 1310b80..45313e0 100644 --- a/src/main/java/cn/somkit/fmt/utils/RocksDBUtils.java +++ b/src/main/java/cn/somkit/fmt/utils/RocksDBUtils.java @@ -23,10 +23,6 @@ public class RocksDBUtils { static { try { String rocksDBPath = RocksDBConfig.RocksDB_Path; //RocksDB文件目录 - //如果使用相对路径,转换为绝对路径 - if(rocksDBPath != null && rocksDBPath.startsWith("./")){ - rocksDBPath = PathUtils.resolve(rocksDBPath); - } PathUtils.directory(rocksDBPath); // 创建RocksDB文件目录 RocksDB.loadLibrary(); Options options = new Options(); diff --git a/src/main/resources/templates/download.html b/src/main/resources/templates/download.html index f53b755..40bb8e4 100644 --- a/src/main/resources/templates/download.html +++ b/src/main/resources/templates/download.html @@ -43,6 +43,10 @@ 在线日志 +
+ 系统设置 + +
diff --git a/src/main/resources/templates/logging.html b/src/main/resources/templates/logging.html index 839226a..0ea0d26 100644 --- a/src/main/resources/templates/logging.html +++ b/src/main/resources/templates/logging.html @@ -36,6 +36,10 @@ 在线日志 +
+ 系统设置 + +
diff --git a/src/main/resources/templates/system.html b/src/main/resources/templates/system.html new file mode 100644 index 0000000..874affa --- /dev/null +++ b/src/main/resources/templates/system.html @@ -0,0 +1,150 @@ + + + + + + + + + + + + + 系统设置 + + + + + +
+
+
+ +
+
+
+ 文件列表 + +
+
+ 文件上传 + +
+
+ 在线日志 + +
+
+ 系统设置 + +
+
+
+
+
+
+
+
+
+
上传文件存放地址:
+
+
+ +
+
+ 相对路径以“./”开头,绝对路径填写完整目录 +
+
+
+
+
+
临时文件存放地址:
+
+
+ +
+
+ 相对路径以“./”开头,绝对路径填写完整目录 +
+
+
+
+
+
日志文件地址:
+
+
+ +
+
+ 相对路径以“./”开头,绝对路径填写完整目录 +
+
+
+
+
+
最大读取展示行数:
+
+
+
+ + + +
+
+
+ 在线日志文件最大读取行数,建议设置较大值以提高性能 +
+
+
+
+
+
读取间隔时间(毫秒):
+
+
+
+ + + +
+
+
+ 在线日志文件读取间隔时间,建议设置较小值以提高性能 +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/upload.html b/src/main/resources/templates/upload.html index d8002ab..893e4fe 100644 --- a/src/main/resources/templates/upload.html +++ b/src/main/resources/templates/upload.html @@ -36,6 +36,10 @@ 在线日志 +
+ 系统设置 + +
diff --git a/版本记录/readme.md b/版本记录/readme.md index ae85579..42f00c8 100644 --- a/版本记录/readme.md +++ b/版本记录/readme.md @@ -22,4 +22,5 @@ 修改RocksDB文件目录配置,使其支持使用相对路径 修改上传文件目录配置,使其支持使用相对路径 新增临时文件存放地址配置,支持相对路径 + 新增系统设置页面,支持在线配置上传文件地址、日志文件地址等参数 ``` \ No newline at end of file