use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class ProjectFileControl method updateConfigFile.
/**
* 保存文件内容 (只能处理文本文件)
*
* @param filePath 相对项目文件的文件夹
* @param filename 读取的文件名
* @param fileText 文件内容
* @return json
*/
@PostMapping(value = "update_config_file", produces = MediaType.APPLICATION_JSON_VALUE)
public String updateConfigFile(String filePath, String filename, String fileText) {
NodeProjectInfoModel pim = getProjectInfoModel();
filePath = StrUtil.emptyToDefault(filePath, File.separator);
// 判断文件后缀
AgentWhitelist whitelist = whitelistDirectoryService.getWhitelist();
Charset charset = AgentWhitelist.checkFileSuffix(whitelist.getAllowEditSuffix(), filename);
FileUtil.writeString(fileText, FileUtil.file(pim.allLib(), filePath, filename), charset);
return JsonMessage.getString(200, "文件写入成功");
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class ProjectFileControl method diffFile.
/**
* 对比文件
*
* @param diffFileVo 参数
* @return json
*/
@PostMapping(value = "diff_file", produces = MediaType.APPLICATION_JSON_VALUE)
public String diffFile(@RequestBody DiffFileVo diffFileVo) {
String id = diffFileVo.getId();
NodeProjectInfoModel projectInfoModel = super.getProjectInfoModel(id);
//
List<DiffFileVo.DiffItem> data = diffFileVo.getData();
Assert.notEmpty(data, "没有要对比的数据");
// 扫描项目目录下面的所有文件
String path = projectInfoModel.allLib();
List<File> files = FileUtil.loopFiles(path);
// 将所有的文件信息组装并签名
List<JSONObject> collect = files.stream().map(file -> {
//
JSONObject item = new JSONObject();
item.put("name", StringUtil.delStartPath(file, path, true));
item.put("sha1", SecureUtil.sha1(file));
return item;
}).collect(Collectors.toList());
// 得到 当前下面文件夹下面所有的文件信息 map
Map<String, String> nowMap = CollStreamUtil.toMap(collect, jsonObject12 -> jsonObject12.getString("name"), jsonObject1 -> jsonObject1.getString("sha1"));
// 将需要对应的信息转为 map
Map<String, String> tryMap = CollStreamUtil.toMap(data, DiffFileVo.DiffItem::getName, DiffFileVo.DiffItem::getSha1);
// 对应需要 当前项目文件夹下没有的和文件内容有变化的
List<JSONObject> canSync = tryMap.entrySet().stream().filter(stringStringEntry -> {
String nowSha1 = nowMap.get(stringStringEntry.getKey());
if (StrUtil.isEmpty(nowSha1)) {
// 不存在
return true;
}
// 如果 文件信息一致 则过滤
return !StrUtil.equals(stringStringEntry.getValue(), nowSha1);
}).map(stringStringEntry -> {
//
JSONObject item = new JSONObject();
item.put("name", stringStringEntry.getKey());
item.put("sha1", stringStringEntry.getValue());
return item;
}).collect(Collectors.toList());
// 对比项目文件夹下有对,但是需要对应对信息里面没有对。此类文件需要删除
List<JSONObject> delArray = nowMap.entrySet().stream().filter(stringStringEntry -> !tryMap.containsKey(stringStringEntry.getKey())).map(stringStringEntry -> {
//
JSONObject item = new JSONObject();
item.put("name", stringStringEntry.getKey());
item.put("sha1", stringStringEntry.getValue());
return item;
}).collect(Collectors.toList());
//
JSONObject result = new JSONObject();
result.put("diff", canSync);
result.put("del", delArray);
return JsonMessage.getString(200, "", result);
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class LogBackController method download.
@RequestMapping(value = "logBack_download", method = RequestMethod.GET)
public String download(String key, String copyId) {
Assert.hasText(key, "请选择对应到文件");
try {
NodeProjectInfoModel pim = getProjectInfoModel();
NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId);
File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem);
if (logBack.exists() && logBack.isDirectory()) {
logBack = FileUtil.file(logBack, key);
ServletUtil.write(getResponse(), logBack);
} else {
return "没有对应文件";
}
} catch (Exception e) {
DefaultSystemLog.getLog().error("下载文件异常", e);
}
return "下载失败。请刷新页面后重试";
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class LogBackController method clear.
@RequestMapping(value = "logBack_delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String clear(String name, String copyId) {
Assert.hasText(name, "没有对应到文件");
NodeProjectInfoModel pim = getProjectInfoModel();
NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId);
File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem);
if (logBack.exists() && logBack.isDirectory()) {
logBack = FileUtil.file(logBack, name);
if (logBack.exists()) {
FileUtil.del(logBack);
return JsonMessage.getString(200, "删除成功");
}
return JsonMessage.getString(500, "没有对应文件");
} else {
return JsonMessage.getString(500, "没有对应文件夹");
}
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class LogBackController method export.
@RequestMapping(value = "export.html", method = RequestMethod.GET)
@ResponseBody
public String export(String copyId) {
NodeProjectInfoModel pim = getProjectInfoModel();
NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId);
File file = copyItem == null ? new File(pim.getLog()) : pim.getLog(copyItem);
if (!file.exists()) {
return JsonMessage.getString(400, "没有日志文件:" + file.getPath());
}
HttpServletResponse response = getResponse();
ServletUtil.write(response, file);
return JsonMessage.getString(200, "");
}
Aggregations