Commit 211fd98ce4523037e6d8f437fc2cf91451049547
1 parent
72434a5d
添加磁盘空间查询接口
Showing
4 changed files
with
81 additions
and
0 deletions
src/main/java/top/panll/assist/config/StartConfig.java
| @@ -35,6 +35,9 @@ public class StartConfig implements CommandLineRunner { | @@ -35,6 +35,9 @@ public class StartConfig implements CommandLineRunner { | ||
| 35 | @Override | 35 | @Override |
| 36 | public void run(String... args) { | 36 | public void run(String... args) { |
| 37 | String record = userSettings.getRecord(); | 37 | String record = userSettings.getRecord(); |
| 38 | + if (!record.endsWith(File.separator)) { | ||
| 39 | + userSettings.setRecord(userSettings.getRecord() + File.separator); | ||
| 40 | + } | ||
| 38 | File recordFile = new File(record); | 41 | File recordFile = new File(record); |
| 39 | if (!recordFile.exists() || !recordFile.isDirectory()) { | 42 | if (!recordFile.exists() || !recordFile.isDirectory()) { |
| 40 | logger.error("[userSettings.record]配置错误,请检查路径是否存在"); | 43 | logger.error("[userSettings.record]配置错误,请检查路径是否存在"); |
src/main/java/top/panll/assist/controller/RecordController.java
| 1 | package top.panll.assist.controller; | 1 | package top.panll.assist.controller; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 4 | import org.slf4j.Logger; | 5 | import org.slf4j.Logger; |
| 5 | import org.slf4j.LoggerFactory; | 6 | import org.slf4j.LoggerFactory; |
| @@ -9,6 +10,7 @@ import org.springframework.http.ResponseEntity; | @@ -9,6 +10,7 @@ import org.springframework.http.ResponseEntity; | ||
| 9 | import org.springframework.web.bind.annotation.*; | 10 | import org.springframework.web.bind.annotation.*; |
| 10 | import top.panll.assist.controller.bean.WVPResult; | 11 | import top.panll.assist.controller.bean.WVPResult; |
| 11 | import top.panll.assist.dto.MergeOrCutTaskInfo; | 12 | import top.panll.assist.dto.MergeOrCutTaskInfo; |
| 13 | +import top.panll.assist.dto.SpaceInfo; | ||
| 12 | import top.panll.assist.service.VideoFileService; | 14 | import top.panll.assist.service.VideoFileService; |
| 13 | import top.panll.assist.utils.PageInfo; | 15 | import top.panll.assist.utils.PageInfo; |
| 14 | 16 | ||
| @@ -271,4 +273,19 @@ public class RecordController { | @@ -271,4 +273,19 @@ public class RecordController { | ||
| 271 | 273 | ||
| 272 | return new ResponseEntity<String>(ret.toString(), HttpStatus.OK); | 274 | return new ResponseEntity<String>(ret.toString(), HttpStatus.OK); |
| 273 | } | 275 | } |
| 276 | + | ||
| 277 | + /** | ||
| 278 | + * 磁盘空间查询 | ||
| 279 | + * @return | ||
| 280 | + */ | ||
| 281 | + @ResponseBody | ||
| 282 | + @GetMapping(value = "/space", produces = "application/json;charset=UTF-8") | ||
| 283 | + public ResponseEntity<String> getSpace() { | ||
| 284 | + JSONObject ret = new JSONObject(); | ||
| 285 | + ret.put("code", 0); | ||
| 286 | + ret.put("msg", "success"); | ||
| 287 | + SpaceInfo spaceInfo = videoFileService.getSpaceInfo(); | ||
| 288 | + ret.put("data", JSON.toJSON(spaceInfo)); | ||
| 289 | + return new ResponseEntity<>(ret.toString(), HttpStatus.OK); | ||
| 290 | + } | ||
| 274 | } | 291 | } |
src/main/java/top/panll/assist/dto/SpaceInfo.java
0 → 100644
| 1 | +package top.panll.assist.dto; | ||
| 2 | + | ||
| 3 | +public class SpaceInfo { | ||
| 4 | + private long total; | ||
| 5 | + private long free; | ||
| 6 | + | ||
| 7 | + public long getTotal() { | ||
| 8 | + return total; | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + public void setTotal(long total) { | ||
| 12 | + this.total = total; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public long getFree() { | ||
| 16 | + return free; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setFree(long free) { | ||
| 20 | + this.free = free; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | +} |
src/main/java/top/panll/assist/service/VideoFileService.java
| @@ -11,6 +11,7 @@ import org.springframework.context.annotation.Bean; | @@ -11,6 +11,7 @@ import org.springframework.context.annotation.Bean; | ||
| 11 | import org.springframework.data.redis.core.StringRedisTemplate; | 11 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 12 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 13 | import org.springframework.util.DigestUtils; | 13 | import org.springframework.util.DigestUtils; |
| 14 | +import top.panll.assist.dto.SpaceInfo; | ||
| 14 | import top.panll.assist.utils.RedisUtil; | 15 | import top.panll.assist.utils.RedisUtil; |
| 15 | import top.panll.assist.dto.MergeOrCutTaskInfo; | 16 | import top.panll.assist.dto.MergeOrCutTaskInfo; |
| 16 | import top.panll.assist.dto.UserSettings; | 17 | import top.panll.assist.dto.UserSettings; |
| @@ -72,6 +73,43 @@ public class VideoFileService { | @@ -72,6 +73,43 @@ public class VideoFileService { | ||
| 72 | } | 73 | } |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 76 | + public SpaceInfo getSpaceInfo(){ | ||
| 77 | + File recordFile = new File(userSettings.getRecord()); | ||
| 78 | + SpaceInfo spaceInfo = new SpaceInfo(); | ||
| 79 | + spaceInfo.setFree(recordFile.getFreeSpace()); | ||
| 80 | + spaceInfo.setTotal(recordFile.getTotalSpace()); | ||
| 81 | + return spaceInfo; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | +// public String getPrintSize(long size) { | ||
| 85 | +// // 如果字节数少于1024,则直接以B为单位,否则先除于1024,后3位因太少无意义 | ||
| 86 | +// if (size < 1024) { | ||
| 87 | +// return String.valueOf(size) + "B"; | ||
| 88 | +// } else { | ||
| 89 | +// size = size / 1024; | ||
| 90 | +// } | ||
| 91 | +// // 如果原字节数除于1024之后,少于1024,则可以直接以KB作为单位 | ||
| 92 | +// // 因为还没有到达要使用另一个单位的时候 | ||
| 93 | +// // 接下去以此类推 | ||
| 94 | +// if (size < 1024) { | ||
| 95 | +// return String.valueOf(size) + "KB"; | ||
| 96 | +// } else { | ||
| 97 | +// size = size / 1024; | ||
| 98 | +// } | ||
| 99 | +// if (size < 1024) { | ||
| 100 | +// // 因为如果以MB为单位的话,要保留最后1位小数, | ||
| 101 | +// // 因此,把此数乘以100之后再取余 | ||
| 102 | +// size = size * 100; | ||
| 103 | +// return String.valueOf((size / 100)) + "." | ||
| 104 | +// + String.valueOf((size % 100)) + "MB"; | ||
| 105 | +// } else { | ||
| 106 | +// // 否则如果要以GB为单位的,先除于1024再作同样的处理 | ||
| 107 | +// size = size * 100 / 1024; | ||
| 108 | +// return String.valueOf((size / 100)) + "." | ||
| 109 | +// + String.valueOf((size % 100)) + "GB"; | ||
| 110 | +// } | ||
| 111 | +// } | ||
| 112 | + | ||
| 75 | public List<File> getStreamList(String app) { | 113 | public List<File> getStreamList(String app) { |
| 76 | File appFile = new File(userSettings.getRecord() + File.separator + app); | 114 | File appFile = new File(userSettings.getRecord() + File.separator + app); |
| 77 | if (appFile != null) { | 115 | if (appFile != null) { |