use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.
the class ScriptController method upload.
@RequestMapping(value = "upload.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String upload() throws IOException {
MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file").setFileExt("bat", "sh");
multipartFileBuilder.setSavePath(AgentConfigBean.getInstance().getTempPathName());
multipartFileBuilder.setUseOriginalFilename(true);
String path = multipartFileBuilder.save();
File file = FileUtil.file(path);
String context = FileUtil.readString(path, ExtConfigBean.getInstance().getConsoleLogCharset());
Assert.hasText(context, "脚本内容为空");
String name = file.getName();
String id = SecureUtil.sha1(name);
NodeScriptModel eModel = nodeScriptServer.getItem(id);
if (eModel != null) {
return JsonMessage.getString(405, "对应脚本模板已经存在啦");
}
eModel = new NodeScriptModel();
eModel.setId(id);
eModel.setName(name);
eModel.setWorkspaceId(getWorkspaceId());
eModel.setContext(context);
file = eModel.getFile(true);
if (file.exists() || file.isDirectory()) {
return JsonMessage.getString(405, "当地id路径文件已经存在来,请修改");
}
nodeScriptServer.addItem(eModel);
return JsonMessage.getString(200, "导入成功");
}
use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.
the class CertificateController method getCertFile.
private String getCertFile(CertModel certModel, boolean add) throws IOException {
String certPath = null;
try {
String path = AgentConfigBean.getInstance().getTempPathName();
MultipartFileBuilder cert = createMultipart().addFieldName("file").setSavePath(path);
certPath = cert.save();
Object val = getUpdateFileInfo(certModel, certPath);
if (val instanceof String) {
return val.toString();
}
JSONObject jsonObject = (JSONObject) val;
String domain = jsonObject.getString("domain");
if (add) {
List<CertModel> array = certService.list();
if (array != null) {
for (CertModel certModel1 : array) {
if (StrUtil.emptyToDefault(domain, "").equals(certModel1.getDomain())) {
return JsonMessage.getString(405, "证书的域名已经存在啦");
}
}
}
} else {
if (!StrUtil.emptyToDefault(domain, "").equals(certModel.getDomain())) {
return JsonMessage.getString(405, "新证书的域名不一致");
}
}
// 移动位置
String temporary = certModel.getWhitePath() + StrUtil.SLASH + certModel.getId() + StrUtil.SLASH;
File pemFile = FileUtil.file(temporary + certModel.getId() + "." + certModel.getType().name());
File keyFile = FileUtil.file(temporary + certModel.getId() + ".key");
if (add) {
if (pemFile.exists()) {
return JsonMessage.getString(405, pemFile.getAbsolutePath() + " 已经被占用啦");
}
if (keyFile.exists()) {
return JsonMessage.getString(405, keyFile.getAbsolutePath() + " 已经被占用啦");
}
}
String pemPath = jsonObject.getString("pemPath");
String keyPath = jsonObject.getString("keyPath");
FileUtil.move(FileUtil.file(pemPath), pemFile, true);
FileUtil.move(FileUtil.file(keyPath), keyFile, true);
certModel.setCert(pemFile.getAbsolutePath());
certModel.setKey(keyFile.getAbsolutePath());
//
certModel.setDomain(domain);
certModel.setExpirationTime(jsonObject.getLongValue("expirationTime"));
certModel.setEffectiveTime(jsonObject.getLongValue("effectiveTime"));
} finally {
if (certPath != null) {
FileUtil.del(certPath);
}
}
return null;
}
use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.
the class TomcatManageController method uploadWar.
/**
* 上传war文件
*
* @param id tomcat id
* @return 操作结果
*/
@RequestMapping(value = "uploadWar", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String uploadWar(String id) {
TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file");
File dir = new File(tomcatInfoModel.getAppBase());
multipartFileBuilder.setSavePath(dir.getAbsolutePath()).setUseOriginalFilename(true);
// 保存
try {
multipartFileBuilder.save();
} catch (IOException e) {
return JsonMessage.getString(500, "上传异常");
}
return JsonMessage.getString(200, "上传成功");
}
use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.
the class TomcatManageController method upload.
/**
* 上传文件
*
* @param id tomcat id
* @param path 文件路径
* @return 操作结果
*/
@RequestMapping(value = "upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String upload(String id, String path) {
TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file");
File dir = new File(tomcatInfoModel.getAppBase().concat(FileUtil.normalize(path)));
multipartFileBuilder.setSavePath(dir.getAbsolutePath()).setUseOriginalFilename(true);
// 保存
try {
multipartFileBuilder.save();
} catch (IOException e) {
return JsonMessage.getString(500, "上传异常");
}
return JsonMessage.getString(200, "上传成功");
}
use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.
the class SystemUpdateController method uploadJar.
@PostMapping(value = "uploadJar.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String uploadJar() throws IOException {
NodeModel nodeModel = tryGetNode();
if (nodeModel != null) {
return NodeForward.requestMultipart(getNode(), getMultiRequest(), NodeUrl.SystemUploadJar).toString();
}
//
Objects.requireNonNull(JpomManifest.getScriptFile());
MultipartFileBuilder multipartFileBuilder = createMultipart();
String absolutePath = ServerConfigBean.getInstance().getUserTempPath().getAbsolutePath();
multipartFileBuilder.setFileExt("jar", "zip").addFieldName("file").setUseOriginalFilename(true).setSavePath(absolutePath);
String path = multipartFileBuilder.save();
// 解析压缩包
File file = JpomManifest.zipFileFind(path, Type.Server, absolutePath);
path = FileUtil.getAbsolutePath(file);
// 基础检查
JsonMessage<Tuple> error = JpomManifest.checkJpomJar(path, Type.Server);
if (error.getCode() != HttpStatus.HTTP_OK) {
return error.toString();
}
Tuple data = error.getData();
String version = data.get(0);
JpomManifest.releaseJar(path, version);
//
backupInfoService.autoBackup();
//
JpomApplication.restart();
return JsonMessage.getString(200, Const.UPGRADE_MSG);
}
Aggregations