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);
}
}
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, "上传成功");
}
Aggregations