Search in sources :

Example 1 with DiffFileVo

use of io.jpom.controller.manage.vo.DiffFileVo in project Jpom by dromara.

the class ProjectFileControl method batchDelete.

@RequestMapping(value = "batch_delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String batchDelete(@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();
    for (DiffFileVo.DiffItem datum : data) {
        File file = FileUtil.file(path, datum.getName());
        if (FileUtil.del(file)) {
            continue;
        }
        return JsonMessage.getString(500, "删除失败");
    }
    return JsonMessage.getString(200, "删除成功");
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) File(java.io.File) DiffFileVo(io.jpom.controller.manage.vo.DiffFileVo)

Example 2 with DiffFileVo

use of io.jpom.controller.manage.vo.DiffFileVo 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);
}
Also used : SecureUtil(cn.hutool.crypto.SecureUtil) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ConsoleService(io.jpom.service.manage.ConsoleService) CollStreamUtil(cn.hutool.core.collection.CollStreamUtil) FileUtils(io.jpom.util.FileUtils) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) HttpUtil(cn.hutool.http.HttpUtil) Charset(java.nio.charset.Charset) BaseEnum(io.jpom.model.BaseEnum) Map(java.util.Map) AbstractProjectCommander(io.jpom.common.commander.AbstractProjectCommander) AgentConfigBean(io.jpom.system.AgentConfigBean) DiffFileVo(io.jpom.controller.manage.vo.DiffFileVo) BaseAgentController(io.jpom.common.BaseAgentController) MediaType(org.springframework.http.MediaType) Set(java.util.Set) ConsoleCommandOp(io.jpom.socket.ConsoleCommandOp) CompressionFileUtil(io.jpom.util.CompressionFileUtil) AfterOpt(io.jpom.model.AfterOpt) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanUtil(cn.hutool.core.util.BooleanUtil) WhitelistDirectoryService(io.jpom.service.WhitelistDirectoryService) TimeUnit(java.util.concurrent.TimeUnit) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) ArrayUtil(cn.hutool.core.util.ArrayUtil) StringUtil(io.jpom.util.StringUtil) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Convert(cn.hutool.core.convert.Convert) AgentWhitelist(io.jpom.model.data.AgentWhitelist) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) ThreadUtil(cn.hutool.core.thread.ThreadUtil) NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) ProjectCommanderUtil(io.jpom.util.ProjectCommanderUtil) Assert(org.springframework.util.Assert) NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File)

Aggregations

DiffFileVo (io.jpom.controller.manage.vo.DiffFileVo)2 NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)2 File (java.io.File)2 CollStreamUtil (cn.hutool.core.collection.CollStreamUtil)1 CollUtil (cn.hutool.core.collection.CollUtil)1 Convert (cn.hutool.core.convert.Convert)1 FileUtil (cn.hutool.core.io.FileUtil)1 ThreadUtil (cn.hutool.core.thread.ThreadUtil)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 BooleanUtil (cn.hutool.core.util.BooleanUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 SecureUtil (cn.hutool.crypto.SecureUtil)1 ServletUtil (cn.hutool.extra.servlet.ServletUtil)1 HttpUtil (cn.hutool.http.HttpUtil)1 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)1 JsonMessage (cn.jiangzeyin.common.JsonMessage)1 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 BaseAgentController (io.jpom.common.BaseAgentController)1