diff --git a/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java b/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java index ec07cc2..e01f5d8 100644 --- a/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java +++ b/tts_service/src/main/java/ai/qiwu/com/tts_service/controller/DeployController.java @@ -85,33 +85,41 @@ public class DeployController { String targetBotAccount = requestBody.getString("targetBotAccount"); String tmpFileFullPathStr = Initialize.AUDIO_DIR+tmpFileRelativePathStr; Path tmpFileFullPath = Paths.get(tmpFileFullPathStr); - if(Files.exists(tmpFileFullPath) - && !Files.isDirectory(tmpFileFullPath) - && StringUtils.endsWith(tmpFileRelativePathStr,".mp3") - && tmpFileRelativePathStr.startsWith("/game_editor_tmp")) { - try { - String tmpFileRelativePathStr2 = tmpFileRelativePathStr.substring("/game_editor_tmp".length()); - if(tmpFileRelativePathStr2.startsWith(File.separator+targetBotAccount)) { - tmpFileRelativePathStr2 = tmpFileRelativePathStr2.substring((File.separator+targetBotAccount).length()); - } - String targetFileRelativePathStr = File.separator+targetBotAccount+tmpFileRelativePathStr2; - String targetFileFullPathStr = Initialize.AUDIO_DIR+targetFileRelativePathStr; - Path targetFileFullPath = Paths.get(targetFileFullPathStr); - File fileDistFile = new File(targetFileFullPathStr); - if(!fileDistFile.getParentFile().exists()) { - fileDistFile.mkdirs(); - } - Files.move(tmpFileFullPath, targetFileFullPath, - StandardCopyOption.REPLACE_EXISTING); - FileUtil.deleteFile(new File(tmpFileFullPathStr)); - return ServerResponse.createBySuccess(targetFileRelativePathStr); - } catch (Exception e) { - e.printStackTrace(); - } - - + if(!Files.exists(tmpFileFullPath) && Files.isDirectory(tmpFileFullPath) ) { + ServerResponse result = ServerResponse.createByError(); + result.setMsg("缓存文件不存在!"); + log.error(tmpFileFullPath.toString()+"路径不存在,或者是目录"); + return result; } - return ServerResponse.createByError(); + if(!StringUtils.endsWith(tmpFileRelativePathStr,".mp3") + && !tmpFileRelativePathStr.startsWith("/game_editor_tmp")) { + ServerResponse result = ServerResponse.createByError(); + result.setMsg("地址前缀或者后缀有问题!"); + log.error(tmpFileFullPath.toString()+"路径不存在,或者是目录"); + return result; + } + + try { + String tmpFileRelativePathStr2 = tmpFileRelativePathStr.substring("/game_editor_tmp".length()); + if(tmpFileRelativePathStr2.startsWith(File.separator+targetBotAccount)) { + tmpFileRelativePathStr2 = tmpFileRelativePathStr2.substring((File.separator+targetBotAccount).length()); + } + String targetFileRelativePathStr = File.separator+targetBotAccount+tmpFileRelativePathStr2; + String targetFileFullPathStr = Initialize.AUDIO_DIR+targetFileRelativePathStr; + Path targetFileFullPath = Paths.get(targetFileFullPathStr); + File fileDistFile = new File(targetFileFullPathStr); + if(!fileDistFile.getParentFile().exists()) { + fileDistFile.mkdirs(); + } + Files.move(tmpFileFullPath, targetFileFullPath, + StandardCopyOption.REPLACE_EXISTING); + FileUtil.deleteFile(new File(tmpFileFullPathStr)); + return ServerResponse.createBySuccess(targetFileRelativePathStr); + } catch (Exception e) { + e.printStackTrace(); + log.error("请求体:"+requestBody); + return ServerResponse.createByError(); + } } @GetMapping("/background/audio")