Search in sources :

Example 26 with NodeProjectInfoModel

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, "文件写入成功");
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) Charset(java.nio.charset.Charset) AgentWhitelist(io.jpom.model.data.AgentWhitelist)

Example 27 with NodeProjectInfoModel

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);
}
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)

Example 28 with NodeProjectInfoModel

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 "下载失败。请刷新页面后重试";
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with NodeProjectInfoModel

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, "没有对应文件夹");
    }
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with NodeProjectInfoModel

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, "");
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) HttpServletResponse(javax.servlet.http.HttpServletResponse) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)40 File (java.io.File)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 JSONObject (com.alibaba.fastjson.JSONObject)11 JSONArray (com.alibaba.fastjson.JSONArray)7 AgentWhitelist (io.jpom.model.data.AgentWhitelist)6 AbstractProjectCommander (io.jpom.common.commander.AbstractProjectCommander)5 Charset (java.nio.charset.Charset)5 DiffFileVo (io.jpom.controller.manage.vo.DiffFileVo)4 ConsoleService (io.jpom.service.manage.ConsoleService)4 CollStreamUtil (cn.hutool.core.collection.CollStreamUtil)3 CollUtil (cn.hutool.core.collection.CollUtil)3 Convert (cn.hutool.core.convert.Convert)3 FileUtil (cn.hutool.core.io.FileUtil)3 ThreadUtil (cn.hutool.core.thread.ThreadUtil)3 ArrayUtil (cn.hutool.core.util.ArrayUtil)3 BooleanUtil (cn.hutool.core.util.BooleanUtil)3 StrUtil (cn.hutool.core.util.StrUtil)3 SecureUtil (cn.hutool.crypto.SecureUtil)3 ServletUtil (cn.hutool.extra.servlet.ServletUtil)3