feat:(unify): 添加修改文件内容接口

This commit is contained in:
opensnail 2024-12-02 23:14:02 +08:00
parent 7ff278d04d
commit d1bc4af726
2 changed files with 27 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.aizuda.snailjob.server.web.controller;
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
import com.aizuda.snailjob.server.web.model.response.SaveFileRequestVO;
import com.aizuda.snailjob.server.web.model.response.ViewFileResponseVO;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
@ -45,4 +46,16 @@ public class FileViewerController {
throw new SnailJobServerException("读取文件失败", e);
}
}
// 保存修改后的文件内容
@PostMapping("/file")
public Boolean saveFile(@RequestBody SaveFileRequestVO requestVO) {
try {
String filePath = Paths.get(requestVO.getFilePath(), requestVO.getFileName()).toString();
Files.writeString(Paths.get(filePath), requestVO.getContent()); // 更新文件内容
return true;
} catch (IOException e) {
throw new SnailJobServerException("文件更新时候", e);
}
}
}

View File

@ -0,0 +1,14 @@
package com.aizuda.snailjob.server.web.model.response;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class SaveFileRequestVO {
private String fileName;
private String filePath;
private String content;
}