Commit 1aafeae65b5afabce7f0c65c5d9eedc5315962e1
1 parent
adbac9f9
添加录像收藏相关接口
Showing
4 changed files
with
144 additions
and
1 deletions
src/main/java/top/panll/assist/controller/RecordController.java
| @@ -14,6 +14,7 @@ import org.springframework.http.ResponseEntity; | @@ -14,6 +14,7 @@ import org.springframework.http.ResponseEntity; | ||
| 14 | import org.springframework.web.bind.annotation.*; | 14 | import org.springframework.web.bind.annotation.*; |
| 15 | import top.panll.assist.controller.bean.WVPResult; | 15 | import top.panll.assist.controller.bean.WVPResult; |
| 16 | import top.panll.assist.dto.MergeOrCutTaskInfo; | 16 | import top.panll.assist.dto.MergeOrCutTaskInfo; |
| 17 | +import top.panll.assist.dto.SignInfo; | ||
| 17 | import top.panll.assist.dto.SpaceInfo; | 18 | import top.panll.assist.dto.SpaceInfo; |
| 18 | import top.panll.assist.service.VideoFileService; | 19 | import top.panll.assist.service.VideoFileService; |
| 19 | import top.panll.assist.utils.PageInfo; | 20 | import top.panll.assist.utils.PageInfo; |
| @@ -290,6 +291,70 @@ public class RecordController { | @@ -290,6 +291,70 @@ public class RecordController { | ||
| 290 | } | 291 | } |
| 291 | 292 | ||
| 292 | /** | 293 | /** |
| 294 | + * 收藏录像(被收藏的录像不会被清理任务清理) | ||
| 295 | + */ | ||
| 296 | + @ApiOperation("收藏录像(被收藏的录像不会被清理任务清理)") | ||
| 297 | + @ApiImplicitParams({ | ||
| 298 | + @ApiImplicitParam(name="app", value = "应用名", required = true, dataTypeClass = String.class), | ||
| 299 | + @ApiImplicitParam(name="stream", value = "流ID", required = true, dataTypeClass = String.class), | ||
| 300 | + }) | ||
| 301 | + @GetMapping(value = "/file/collection/add") | ||
| 302 | + @ResponseBody | ||
| 303 | + public WVPResult<String> collection( | ||
| 304 | + @RequestParam(required = true) String app, | ||
| 305 | + @RequestParam(required = true) String stream){ | ||
| 306 | + | ||
| 307 | + boolean collectionResult = videoFileService.collection(app, stream); | ||
| 308 | + WVPResult<String> result = new WVPResult<>(); | ||
| 309 | + result.setCode(0); | ||
| 310 | + result.setMsg(collectionResult ?"success":"error"); | ||
| 311 | + return result; | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * 移除收藏录像 | ||
| 316 | + */ | ||
| 317 | + @ApiOperation("移除收藏录像") | ||
| 318 | + @ApiImplicitParams({ | ||
| 319 | + @ApiImplicitParam(name="app", value = "应用名", required = true, dataTypeClass = String.class), | ||
| 320 | + @ApiImplicitParam(name="stream", value = "流ID", required = true, dataTypeClass = String.class), | ||
| 321 | + }) | ||
| 322 | + @GetMapping(value = "/file/collection/remove") | ||
| 323 | + @ResponseBody | ||
| 324 | + public WVPResult<String> removeCollection( | ||
| 325 | + @RequestParam(required = true) String app, | ||
| 326 | + @RequestParam(required = true) String stream){ | ||
| 327 | + | ||
| 328 | + boolean collectionResult = videoFileService.removeCollection(app, stream); | ||
| 329 | + WVPResult<String> result = new WVPResult<>(); | ||
| 330 | + result.setCode(0); | ||
| 331 | + result.setMsg(collectionResult ?"success":"error"); | ||
| 332 | + return result; | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + /** | ||
| 336 | + * 收藏录像列表 | ||
| 337 | + */ | ||
| 338 | + @ApiOperation("收藏录像列表") | ||
| 339 | + @ApiImplicitParams({ | ||
| 340 | + @ApiImplicitParam(name="app", value = "应用名", required = false, dataTypeClass = String.class), | ||
| 341 | + @ApiImplicitParam(name="stream", value = "流ID", required = false, dataTypeClass = String.class), | ||
| 342 | + }) | ||
| 343 | + @GetMapping(value = "/file/collection/list") | ||
| 344 | + @ResponseBody | ||
| 345 | + public WVPResult<List<SignInfo>> collectionList( | ||
| 346 | + @RequestParam(required = false) String app, | ||
| 347 | + @RequestParam(required = false) String stream){ | ||
| 348 | + | ||
| 349 | + List<SignInfo> signInfos = videoFileService.getCollectionList(app, stream); | ||
| 350 | + WVPResult<List<SignInfo>> result = new WVPResult<>(); | ||
| 351 | + result.setCode(0); | ||
| 352 | + result.setMsg(signInfos != null ?"success":"error"); | ||
| 353 | + result.setData(signInfos); | ||
| 354 | + return result; | ||
| 355 | + } | ||
| 356 | + | ||
| 357 | + /** | ||
| 293 | * 中止视频裁剪合并任务列表 | 358 | * 中止视频裁剪合并任务列表 |
| 294 | */ | 359 | */ |
| 295 | @ApiOperation("中止视频裁剪合并任务列表(暂不支持)") | 360 | @ApiOperation("中止视频裁剪合并任务列表(暂不支持)") |
src/main/java/top/panll/assist/dto/MergeOrCutTaskInfo.java
src/main/java/top/panll/assist/dto/SignInfo.java
0 → 100644
| 1 | +package top.panll.assist.dto; | ||
| 2 | + | ||
| 3 | +public class SignInfo { | ||
| 4 | + private String app; | ||
| 5 | + private String stream; | ||
| 6 | + | ||
| 7 | + public String getApp() { | ||
| 8 | + return app; | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + public void setApp(String app) { | ||
| 12 | + this.app = app; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public String getStream() { | ||
| 16 | + return stream; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setStream(String stream) { | ||
| 20 | + this.stream = stream; | ||
| 21 | + } | ||
| 22 | +} |
src/main/java/top/panll/assist/service/VideoFileService.java
| @@ -3,12 +3,14 @@ package top.panll.assist.service; | @@ -3,12 +3,14 @@ package top.panll.assist.service; | ||
| 3 | import net.bramp.ffmpeg.FFprobe; | 3 | import net.bramp.ffmpeg.FFprobe; |
| 4 | import net.bramp.ffmpeg.probe.FFmpegProbeResult; | 4 | import net.bramp.ffmpeg.probe.FFmpegProbeResult; |
| 5 | import net.bramp.ffmpeg.progress.Progress; | 5 | import net.bramp.ffmpeg.progress.Progress; |
| 6 | +import org.apache.commons.io.FileUtils; | ||
| 6 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
| 7 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | import org.springframework.data.redis.core.RedisTemplate; | 10 | import org.springframework.data.redis.core.RedisTemplate; |
| 10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.util.DigestUtils; | 12 | import org.springframework.util.DigestUtils; |
| 13 | +import top.panll.assist.dto.SignInfo; | ||
| 12 | import top.panll.assist.dto.SpaceInfo; | 14 | import top.panll.assist.dto.SpaceInfo; |
| 13 | import top.panll.assist.utils.RedisUtil; | 15 | import top.panll.assist.utils.RedisUtil; |
| 14 | import top.panll.assist.dto.MergeOrCutTaskInfo; | 16 | import top.panll.assist.dto.MergeOrCutTaskInfo; |
| @@ -497,4 +499,59 @@ public class VideoFileService { | @@ -497,4 +499,59 @@ public class VideoFileService { | ||
| 497 | // } | 499 | // } |
| 498 | return false; | 500 | return false; |
| 499 | } | 501 | } |
| 502 | + | ||
| 503 | + public boolean collection(String app, String stream) { | ||
| 504 | + File streamFile = new File(userSettings.getRecord() + File.separator + app + File.separator + stream); | ||
| 505 | + boolean result = false; | ||
| 506 | + if (streamFile.exists() && streamFile.isDirectory() && streamFile.canWrite()) { | ||
| 507 | + File signFile = new File(streamFile.getAbsolutePath() + File.separator + "sign"); | ||
| 508 | + try { | ||
| 509 | + result = signFile.createNewFile(); | ||
| 510 | + } catch (IOException e) { | ||
| 511 | + logger.error("[收藏文件]失败,{}/{}", app, stream); | ||
| 512 | + } | ||
| 513 | + } | ||
| 514 | + return result; | ||
| 515 | + } | ||
| 516 | + | ||
| 517 | + public boolean removeCollection(String app, String stream) { | ||
| 518 | + File signFile = new File(userSettings.getRecord() + File.separator + app + File.separator + stream + File.separator + "sign"); | ||
| 519 | + boolean result = false; | ||
| 520 | + if (signFile.exists() && signFile.isFile()) { | ||
| 521 | + result = signFile.delete(); | ||
| 522 | + } | ||
| 523 | + return result; | ||
| 524 | + } | ||
| 525 | + | ||
| 526 | + public List<SignInfo> getCollectionList(String app, String stream) { | ||
| 527 | + List<File> appList = this.getAppList(true); | ||
| 528 | + List<SignInfo> result = new ArrayList<>(); | ||
| 529 | + if (appList.size() > 0) { | ||
| 530 | + for (File appFile : appList) { | ||
| 531 | + if (app != null) { | ||
| 532 | + if (!app.equals(appFile.getName())) { | ||
| 533 | + continue; | ||
| 534 | + } | ||
| 535 | + } | ||
| 536 | + List<File> streamList = getStreamList(appFile, true); | ||
| 537 | + if (streamList.size() > 0) { | ||
| 538 | + for (File streamFile : streamList) { | ||
| 539 | + if (stream != null) { | ||
| 540 | + if (!stream.equals(streamFile.getName())) { | ||
| 541 | + continue; | ||
| 542 | + } | ||
| 543 | + } | ||
| 544 | + File signFile = new File(streamFile.getAbsolutePath() + File.separator + "sign"); | ||
| 545 | + if (signFile.exists()) { | ||
| 546 | + SignInfo signInfo = new SignInfo(); | ||
| 547 | + signInfo.setApp(appFile.getName()); | ||
| 548 | + signInfo.setStream(streamFile.getName()); | ||
| 549 | + result.add(signInfo); | ||
| 550 | + } | ||
| 551 | + } | ||
| 552 | + } | ||
| 553 | + } | ||
| 554 | + } | ||
| 555 | + return result; | ||
| 556 | + } | ||
| 500 | } | 557 | } |