Search in sources :

Example 11 with MultipartFileBuilder

use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.

the class SshInstallAgentController method uploadAgent.

@RequestMapping(value = "upload_agent.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
@SystemPermission
public String uploadAgent() throws Exception {
    ServerConfigBean instance = ServerConfigBean.getInstance();
    String tempFilePath = instance.getUserTempPath().getAbsolutePath();
    MultipartFileBuilder multipartFileBuilder = createMultipart().setFileExt("zip").addFieldName("file").setSavePath(tempFilePath);
    String filePath = multipartFileBuilder.save();
    File tempAgent = FileUtil.file(tempFilePath, "temp_agent");
    FileUtil.del(tempAgent);
    // 解析压缩包
    File jarFile = JpomManifest.zipFileFind(filePath, Type.Agent, FileUtil.getAbsolutePath(tempAgent));
    // 验证文件是否正确
    JsonMessage<Tuple> tupleJsonMessage = JpomManifest.checkJpomJar(FileUtil.getAbsolutePath(jarFile), Type.Agent, false);
    Assert.state(tupleJsonMessage.getCode() == 200, tupleJsonMessage::getMsg);
    // 
    File outFle = FileUtil.file(tempFilePath, Type.Agent.name() + "_" + IdUtil.fastSimpleUUID());
    try {
        this.unZipGetTag(filePath, outFle);
        // 保存插件包
        File agentZipPath = instance.getAgentZipPath();
        FileUtil.copy(FileUtil.file(filePath), agentZipPath, true);
        return JsonMessage.getString(200, "上传成功");
    } finally {
        FileUtil.del(filePath);
        FileUtil.del(jarFile);
    }
}
Also used : MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) ZipFile(java.util.zip.ZipFile) File(java.io.File) ServerConfigBean(io.jpom.system.ServerConfigBean) Tuple(cn.hutool.core.lang.Tuple) SystemPermission(io.jpom.permission.SystemPermission) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with MultipartFileBuilder

use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.

the class NodeUpdateController method uploadAgent.

@RequestMapping(value = "upload_agent", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission
@Feature(method = MethodFeature.UPLOAD)
public String uploadAgent() throws IOException {
    String saveDir = ServerConfigBean.getInstance().getAgentPath().getAbsolutePath();
    MultipartFileBuilder multipartFileBuilder = createMultipart();
    multipartFileBuilder.setFileExt("jar", "zip").addFieldName("file").setUseOriginalFilename(true).setSavePath(saveDir);
    String path = multipartFileBuilder.save();
    // 解析压缩包
    File file = JpomManifest.zipFileFind(path, Type.Agent, saveDir);
    path = FileUtil.getAbsolutePath(file);
    // 基础检查
    JsonMessage<Tuple> error = JpomManifest.checkJpomJar(path, Type.Agent, false);
    if (error.getCode() != HttpStatus.HTTP_OK) {
        FileUtil.del(path);
        return error.toString();
    }
    // 保存文件
    this.saveAgentFile(error.getData());
    return JsonMessage.getString(200, "上传成功");
}
Also used : MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) Tuple(cn.hutool.core.lang.Tuple) SystemPermission(io.jpom.permission.SystemPermission) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)12 File (java.io.File)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ClassFeature (io.jpom.permission.ClassFeature)6 Feature (io.jpom.permission.Feature)6 MethodFeature (io.jpom.permission.MethodFeature)6 Tuple (cn.hutool.core.lang.Tuple)3 SystemPermission (io.jpom.permission.SystemPermission)3 JSONObject (com.alibaba.fastjson.JSONObject)2 AfterOpt (io.jpom.model.AfterOpt)2 TomcatInfoModel (io.jpom.model.data.TomcatInfoModel)2 IOException (java.io.IOException)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)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