|
@@ -7,10 +7,10 @@
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
* subject to the following conditions:
|
|
* subject to the following conditions:
|
|
|
-
|
|
|
|
|
|
|
+ * <p>
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
* copies or substantial portions of the Software.
|
|
* copies or substantial portions of the Software.
|
|
|
-
|
|
|
|
|
|
|
+ * <p>
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
@@ -25,18 +25,11 @@ package net.mingsoft.cms.action;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.io.file.FileNameUtil;
|
|
import cn.hutool.core.io.file.FileNameUtil;
|
|
|
-import cn.hutool.core.map.MapUtil;
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.json.JSONArray;
|
|
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.baidu.ueditor.define.BaseState;
|
|
|
|
|
-import com.baidu.ueditor.define.State;
|
|
|
|
|
-import io.github.xcodeding.UeditorActionEnter;
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
-import net.mingsoft.base.constant.Const;
|
|
|
|
|
import net.mingsoft.base.entity.ResultData;
|
|
import net.mingsoft.base.entity.ResultData;
|
|
|
-import net.mingsoft.base.exception.BusinessException;
|
|
|
|
|
import net.mingsoft.base.util.BundleUtil;
|
|
import net.mingsoft.base.util.BundleUtil;
|
|
|
import net.mingsoft.basic.action.BaseFileAction;
|
|
import net.mingsoft.basic.action.BaseFileAction;
|
|
|
import net.mingsoft.basic.bean.UploadConfigBean;
|
|
import net.mingsoft.basic.bean.UploadConfigBean;
|
|
@@ -44,14 +37,16 @@ import net.mingsoft.basic.entity.AppEntity;
|
|
|
import net.mingsoft.basic.service.IUploadBaseService;
|
|
import net.mingsoft.basic.service.IUploadBaseService;
|
|
|
import net.mingsoft.basic.util.BasicUtil;
|
|
import net.mingsoft.basic.util.BasicUtil;
|
|
|
import net.mingsoft.basic.util.SpringUtil;
|
|
import net.mingsoft.basic.util.SpringUtil;
|
|
|
-import net.mingsoft.config.MSProperties;
|
|
|
|
|
|
|
+import net.mingsoft.cms.bean.EditorStateBean;
|
|
|
import net.mingsoft.mdiy.util.ConfigUtil;
|
|
import net.mingsoft.mdiy.util.ConfigUtil;
|
|
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.codec.binary.Hex;
|
|
import org.apache.commons.codec.binary.Hex;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -61,20 +56,22 @@ import java.util.*;
|
|
|
public class BaseAction extends BaseFileAction {
|
|
public class BaseAction extends BaseFileAction {
|
|
|
/**
|
|
/**
|
|
|
* 读取国际化资源文件(没有占位符号的),优先模块对应的资源文件,如果模块资源文件找不到就会优先基础层
|
|
* 读取国际化资源文件(没有占位符号的),优先模块对应的资源文件,如果模块资源文件找不到就会优先基础层
|
|
|
|
|
+ *
|
|
|
* @param key 国际化文件key
|
|
* @param key 国际化文件key
|
|
|
* @return 国际化字符串
|
|
* @return 国际化字符串
|
|
|
*/
|
|
*/
|
|
|
protected String getResString(String key) {
|
|
protected String getResString(String key) {
|
|
|
- return this.getResString(key,"");
|
|
|
|
|
|
|
+ return this.getResString(key, "");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 读取国际化资源文件,优先模块对应的资源文件,如果模块资源文件找不到就会优先基础层
|
|
* 读取国际化资源文件,优先模块对应的资源文件,如果模块资源文件找不到就会优先基础层
|
|
|
- * @param key 国际化文件key
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param key 国际化文件key
|
|
|
* @param params 拼接值
|
|
* @param params 拼接值
|
|
|
* @return 国际化字符串
|
|
* @return 国际化字符串
|
|
|
*/
|
|
*/
|
|
|
- protected String getResString(String key,String... params) {
|
|
|
|
|
|
|
+ protected String getResString(String key, String... params) {
|
|
|
// TODO Auto-generated method stub
|
|
// TODO Auto-generated method stub
|
|
|
String str = "";
|
|
String str = "";
|
|
|
try {
|
|
try {
|
|
@@ -84,7 +81,7 @@ public class BaseAction extends BaseFileAction {
|
|
|
str = str.replace("{" + i + "}", params[i]);
|
|
str = str.replace("{" + i + "}", params[i]);
|
|
|
}
|
|
}
|
|
|
} catch (MissingResourceException e) {
|
|
} catch (MissingResourceException e) {
|
|
|
- str = BundleUtil.getString(net.mingsoft.cms.constant.Const.RESOURCES, key,params);
|
|
|
|
|
|
|
+ str = BundleUtil.getString(net.mingsoft.cms.constant.Const.RESOURCES, key, params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
return str;
|
|
@@ -93,24 +90,14 @@ public class BaseAction extends BaseFileAction {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 抽取百度编辑器执行公共部分
|
|
* 抽取百度编辑器执行公共部分
|
|
|
- * @param request 请求
|
|
|
|
|
- * @param upfile 文件
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param request 请求
|
|
|
|
|
+ * @param upfile 文件
|
|
|
* @param execFileConfigMap 上传大小配置Map 应包含 imageMaxSize、videoMaxSize、fileMaxSize
|
|
* @param execFileConfigMap 上传大小配置Map 应包含 imageMaxSize、videoMaxSize、fileMaxSize
|
|
|
- * @param version 编辑器版本
|
|
|
|
|
|
|
+ * @param version 编辑器版本
|
|
|
* @return 执行结果响应
|
|
* @return 执行结果响应
|
|
|
*/
|
|
*/
|
|
|
- public String exec(HttpServletRequest request, MultipartFile upfile, Map execFileConfigMap, String version){
|
|
|
|
|
- String uploadFolderPath = MSProperties.upload.path;
|
|
|
|
|
- String uploadMapping = MSProperties.upload.mapping;
|
|
|
|
|
-
|
|
|
|
|
- Map uploadConfig = ConfigUtil.getMap("文件上传配置");
|
|
|
|
|
- if (MapUtil.isNotEmpty(uploadConfig)){
|
|
|
|
|
- uploadFolderPath = uploadConfig.get("uploadPath").toString();
|
|
|
|
|
- uploadMapping = uploadConfig.get("uploadMapping").toString();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 获取真实完整上传路径
|
|
|
|
|
- String rootPath = FileUtil.isAbsolutePath(uploadFolderPath) ? uploadFolderPath : BasicUtil.getRealPath(uploadFolderPath);
|
|
|
|
|
|
|
+ public String exec(HttpServletRequest request, MultipartFile upfile, Map execFileConfigMap, String version) {
|
|
|
|
|
|
|
|
Map execConfigMap = new HashMap();
|
|
Map execConfigMap = new HashMap();
|
|
|
execConfigMap.putAll(execFileConfigMap);
|
|
execConfigMap.putAll(execFileConfigMap);
|
|
@@ -124,8 +111,6 @@ public class BaseAction extends BaseFileAction {
|
|
|
|
|
|
|
|
String filePathFormat = uploadPath.concat("{time}");
|
|
String filePathFormat = uploadPath.concat("{time}");
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
execConfigMap.put("imagePathFormat", filePathFormat);
|
|
execConfigMap.put("imagePathFormat", filePathFormat);
|
|
|
execConfigMap.put("filePathFormat", filePathFormat);
|
|
execConfigMap.put("filePathFormat", filePathFormat);
|
|
|
execConfigMap.put("videoPathFormat", filePathFormat);
|
|
execConfigMap.put("videoPathFormat", filePathFormat);
|
|
@@ -133,100 +118,203 @@ public class BaseAction extends BaseFileAction {
|
|
|
execConfigMap.put("scrawlPathFormat", filePathFormat);
|
|
execConfigMap.put("scrawlPathFormat", filePathFormat);
|
|
|
execConfigMap.put("snapscreenPathFormat", filePathFormat);
|
|
execConfigMap.put("snapscreenPathFormat", filePathFormat);
|
|
|
|
|
|
|
|
- String execConfig = JSONUtil.toJsonStr(execConfigMap);
|
|
|
|
|
|
|
+ String action = BasicUtil.getString("action");
|
|
|
|
|
+ // 判断当前编辑器什么操作
|
|
|
|
|
+ switch (action) {
|
|
|
|
|
+ case "uploadscrawl":
|
|
|
|
|
+ // 上传涂鸦文件
|
|
|
|
|
+ return uploadEditorScrawlFile(request, uploadPath);
|
|
|
|
|
+ case "uploadimage":
|
|
|
|
|
+ case "uploadvideo":
|
|
|
|
|
+ case "uploadfile":
|
|
|
|
|
+ // 上传文件
|
|
|
|
|
+ return uploadEditorFile(uploadPath, upfile);
|
|
|
|
|
+ case "catchimage":
|
|
|
|
|
+ // 抓取网络图片到本地
|
|
|
|
|
+ return catchImage(request, uploadPath);
|
|
|
|
|
+ default:
|
|
|
|
|
+ // 获取编辑器配置
|
|
|
|
|
+ return getEditorConfig(execConfigMap, BasicUtil.getRealPath(StrUtil.format("static/plugins/ueditor/{}/config.json", version)));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传编辑器涂鸦图片
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param uploadPath 上传路径
|
|
|
|
|
+ * @param request HttpServletRequest
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private String uploadEditorScrawlFile(HttpServletRequest request, String uploadPath){
|
|
|
|
|
+ String base64 = request.getParameter("upfile");
|
|
|
|
|
+ byte[] bytes = Base64.decodeBase64(base64);
|
|
|
|
|
+ if (bytes == null) {
|
|
|
|
|
+ return new EditorStateBean(false, "上传涂鸦图片失败").toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 尝试从流中获取后缀地址
|
|
|
|
|
+ MultipartFile file = net.mingsoft.basic.util.FileUtil.bytesToMultipartFile(bytes, "png");
|
|
|
|
|
+
|
|
|
|
|
+ if (ObjectUtil.isNull(file)) {
|
|
|
|
|
+ return new EditorStateBean(false, "上传涂鸦图片失败").toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ UploadConfigBean bean = new UploadConfigBean(uploadPath, file, null, true);
|
|
|
|
|
+ bean.setFileSize(bytes.length);
|
|
|
|
|
+ bean.setFileName(file.getName());
|
|
|
|
|
+ EditorStateBean state = new EditorStateBean();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ state = this.uploadFile(bean);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ LOG.debug("上传编辑器涂鸦文件失败");
|
|
|
|
|
+ return new EditorStateBean(false, "上传涂鸦文件失败").toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 抓取远程图片保存到本地
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param request HttpServletRequest
|
|
|
|
|
+ * @param uploadPath 上传路径
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private String catchImage(HttpServletRequest request, String uploadPath) {
|
|
|
|
|
+ // 获取图片地址
|
|
|
|
|
+ String[] remotes = request.getParameterValues("source[]");
|
|
|
|
|
+ EditorStateBean multiState = new EditorStateBean(true);
|
|
|
|
|
+ List<EditorStateBean> states = new ArrayList<>();
|
|
|
|
|
+ for (String remote : remotes) {
|
|
|
|
|
+ if (StringUtils.isBlank(remote)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 根据文件后缀当默认值,防止出现某些文件通过字节流获取后缀为空的情况
|
|
|
|
|
+ String suffix = FileNameUtil.getSuffix(remote);
|
|
|
|
|
+ suffix = StrUtil.isBlank(suffix) ? "png" : suffix;
|
|
|
|
|
+
|
|
|
|
|
+ // 转成multipartFile对象方便组装成上传bean
|
|
|
|
|
+ MultipartFile file = net.mingsoft.basic.util.FileUtil.remoteUrlToMultipartFile(remote, suffix);
|
|
|
|
|
+ if (file == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ UploadConfigBean bean = new UploadConfigBean(uploadPath, file, null, true);
|
|
|
|
|
+ bean.setFileSize(file.getSize());
|
|
|
|
|
+ bean.setFileName(file.getName());
|
|
|
|
|
|
|
|
- // 如果upfile不为空,说明此处操作时上传附件操作
|
|
|
|
|
- if (upfile != null){
|
|
|
|
|
- State state = null;
|
|
|
|
|
- String upFileMainName = FileNameUtil.mainName(upfile.getOriginalFilename());
|
|
|
|
|
- if (StringUtils.isBlank(upFileMainName)){
|
|
|
|
|
- return new BaseState(false, getResString("err.error",getResString("file.name"))).toJSONString();
|
|
|
|
|
|
|
+ EditorStateBean state = new EditorStateBean();
|
|
|
|
|
+ try {
|
|
|
|
|
+ state = this.uploadFile(bean);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ LOG.debug("抓取图片失败");
|
|
|
|
|
+ state = new EditorStateBean(false, "抓取图片失败");
|
|
|
}
|
|
}
|
|
|
- // 组装uploadConfigBean上传使用
|
|
|
|
|
- UploadConfigBean bean = new UploadConfigBean(uploadPath, upfile, null, true);
|
|
|
|
|
- bean.setFileSize(upfile.getSize());
|
|
|
|
|
- bean.setFileName(upfile.getOriginalFilename());
|
|
|
|
|
|
|
+ // 这里还需要把源文件地址添加到结果中
|
|
|
|
|
+ if (state.isSuccess()) {
|
|
|
|
|
+ state.put("state", "SUCCESS");
|
|
|
|
|
+ state.put("source", remote);
|
|
|
|
|
+ }
|
|
|
|
|
+ states.add(state);
|
|
|
|
|
+ }
|
|
|
|
|
+ multiState.put("list", states);
|
|
|
|
|
+ return multiState.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传编辑器文件
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param uploadPath 上传路径
|
|
|
|
|
+ * @param upfile 文件
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private String uploadEditorFile(String uploadPath, MultipartFile upfile) {
|
|
|
|
|
+ String upFileMainName = FileNameUtil.mainName(upfile.getOriginalFilename());
|
|
|
|
|
+ if (StringUtils.isBlank(upFileMainName)) {
|
|
|
|
|
+ return new EditorStateBean(false, getResString("err.error", getResString("file.name"))).toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 组装uploadConfigBean上传使用
|
|
|
|
|
+ UploadConfigBean bean = new UploadConfigBean(uploadPath, upfile, null, true);
|
|
|
|
|
+ bean.setFileSize(upfile.getSize());
|
|
|
|
|
+ bean.setFileName(upfile.getOriginalFilename());
|
|
|
|
|
+ try {
|
|
|
|
|
+ return this.uploadFile(bean).toString();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return new EditorStateBean(false, "上传图片失败").toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取编辑器配置
|
|
|
|
|
+ * @param configJson 配置json
|
|
|
|
|
+ * @param jsonPath json文件路径
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private String getEditorConfig(Map configJson, String jsonPath) {
|
|
|
|
|
+ // 读取本地json文件
|
|
|
|
|
+ String _configJson = FileUtil.readString(jsonPath, StandardCharsets.UTF_8);
|
|
|
|
|
+ // 过滤中文字符串
|
|
|
|
|
+ _configJson = _configJson.replaceAll("/\\*[\\s\\S]*?\\*/", "");
|
|
|
|
|
+ Map jsonMap = JSONUtil.toBean(_configJson, Map.class);
|
|
|
|
|
+ // 拿自定义数据替换json中某些数据
|
|
|
|
|
+ jsonMap.putAll(configJson);
|
|
|
|
|
+ return JSONUtil.toJsonStr(jsonMap);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传文件到本地并且组装成百度编辑器格式返回
|
|
|
|
|
+ * @param bean 上传配置
|
|
|
|
|
+ * @return 上传结果
|
|
|
|
|
+ * @throws IOException 抛出异常
|
|
|
|
|
+ */
|
|
|
|
|
+ private EditorStateBean uploadFile(UploadConfigBean bean) throws IOException {
|
|
|
|
|
+ // 判断是依赖ms-file插件
|
|
|
|
|
+ String type = ConfigUtil.getString("存储设置", "storeSelect");
|
|
|
|
|
+ IUploadBaseService uploadBaseService = null;
|
|
|
|
|
+ EditorStateBean state = new EditorStateBean(true);
|
|
|
|
|
+ // 单个文件上传计算下各个参数值避免重复上传
|
|
|
|
|
+ if (StringUtils.isBlank(bean.getFileIdentifier())) {
|
|
|
try {
|
|
try {
|
|
|
- // 判断是依赖ms-file插件
|
|
|
|
|
- String type = ConfigUtil.getString("存储设置", "storeSelect");
|
|
|
|
|
- IUploadBaseService uploadBaseService = null;
|
|
|
|
|
- // 单个文件上传计算下各个参数值避免重复上传
|
|
|
|
|
- if (StringUtils.isBlank(bean.getFileIdentifier())){
|
|
|
|
|
- try {
|
|
|
|
|
- bean.setFileIdentifier(String.valueOf(Hex.encodeHex(MessageDigest.getInstance("MD5").digest(bean.getFile().getBytes()))));
|
|
|
|
|
- } catch (NoSuchAlgorithmException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (StringUtils.isNotBlank(type)) {
|
|
|
|
|
- //ms-file 插件启用
|
|
|
|
|
- uploadBaseService = (IUploadBaseService) SpringUtil.getBean(type);
|
|
|
|
|
- }
|
|
|
|
|
- ResultData resultData = null;
|
|
|
|
|
- // 根据不同类型决定上传逻辑
|
|
|
|
|
- if (uploadBaseService != null) {
|
|
|
|
|
- resultData = uploadBaseService.upload(bean);
|
|
|
|
|
- } else {
|
|
|
|
|
- resultData = this.upload(bean);
|
|
|
|
|
- }
|
|
|
|
|
- if (resultData.isSuccess()) {
|
|
|
|
|
- // 组装百度编辑器格式
|
|
|
|
|
- state = new BaseState(true);
|
|
|
|
|
- state.putInfo("original", upfile.getOriginalFilename());
|
|
|
|
|
- state.putInfo("size", upfile.getSize());
|
|
|
|
|
- state.putInfo("title", FileNameUtil.getName(resultData.getData(String.class)));
|
|
|
|
|
- state.putInfo("type", "." + FileNameUtil.getSuffix(upfile.getOriginalFilename()));
|
|
|
|
|
- // 由于百度编辑器不是正常的uploadConfigBean,是无法正常通过getFileIdentifier获取到文件标识的,所以在这里做一个容错处理
|
|
|
|
|
- state.putInfo("fileIdentifier", bean.getFileIdentifier());
|
|
|
|
|
- // 判断是否有contentPath
|
|
|
|
|
- String contextPath = BasicUtil.getContextPath();
|
|
|
|
|
- String filePath = resultData.getData(String.class);
|
|
|
|
|
- if (StringUtils.isNotBlank(filePath) && !filePath.startsWith("http")) {
|
|
|
|
|
- filePath = (contextPath.equals("/") ? "" : contextPath) + filePath;
|
|
|
|
|
- }
|
|
|
|
|
- state.putInfo("url", filePath);
|
|
|
|
|
- } else {
|
|
|
|
|
- state = new BaseState(false, resultData.getMsg());
|
|
|
|
|
- }
|
|
|
|
|
- return state.toJSONString();
|
|
|
|
|
|
|
+ bean.setFileIdentifier(String.valueOf(Hex.encodeHex(MessageDigest.getInstance("MD5").digest(bean.getFile().getBytes()))));
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
- return new BaseState(false, 500).toJSONString();
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- //过滤非法上传路径
|
|
|
|
|
- if (execConfig != null && (execConfig.contains("../") || execConfig.contains("..\\"))) {
|
|
|
|
|
- return new BaseState(false, BundleUtil.getString(Const.RESOURCES,"err.error",BundleUtil.getString(net.mingsoft.basic.constant.Const.RESOURCES,"file.path"))).toJSONString();
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(type)) {
|
|
|
|
|
+ //ms-file 插件启用
|
|
|
|
|
+ uploadBaseService = (IUploadBaseService) SpringUtil.getBean(type);
|
|
|
}
|
|
}
|
|
|
- UeditorActionEnter actionEnter = new UeditorActionEnter(upfile,request, rootPath, execConfig, BasicUtil.getRealPath(""), BasicUtil.getRealPath(StrUtil.format("static/plugins/ueditor/{}/config.json",version)));
|
|
|
|
|
- String result = actionEnter.exec();
|
|
|
|
|
- // 获取请求类型
|
|
|
|
|
- String action = BasicUtil.getString("action");
|
|
|
|
|
- Map jsonMap = JSONUtil.toBean(result,Map.class);
|
|
|
|
|
- // 这里会有图片复制粘贴情况
|
|
|
|
|
- if ("catchimage".equalsIgnoreCase(action) && jsonMap.get("state").equals("SUCCESS")) {
|
|
|
|
|
- // 处理绝对路径和项目名情况
|
|
|
|
|
- JSONArray fileUrls = JSONUtil.parseArray(MapUtil.getStr(jsonMap, "list", "[]"));
|
|
|
|
|
- String url = "";
|
|
|
|
|
- List<JSONObject> list = new ArrayList<>();
|
|
|
|
|
- // 循环上传文件,判断是否有项目名和绝对路径
|
|
|
|
|
- for (Object fileUrl : fileUrls) {
|
|
|
|
|
- JSONObject jsonObject = (JSONObject) fileUrl;
|
|
|
|
|
- url = jsonObject.getStr("url");
|
|
|
|
|
- // 判断是否有contentPath
|
|
|
|
|
- String contextPath = BasicUtil.getContextPath();
|
|
|
|
|
- if (StringUtils.isNotBlank(url) && !url.startsWith("http")) {
|
|
|
|
|
- url = "/".concat(uploadMapping.replaceAll("/([\\s\\S]*)/\\*\\*", "$1")).concat(url + "");
|
|
|
|
|
- url = (contextPath.equals("/") ? "" : contextPath) + url;
|
|
|
|
|
- }
|
|
|
|
|
- jsonObject.set("url", url);
|
|
|
|
|
- list.add(jsonObject);
|
|
|
|
|
|
|
+ ResultData resultData = null;
|
|
|
|
|
+ // 根据不同类型决定上传逻辑
|
|
|
|
|
+ if (uploadBaseService != null) {
|
|
|
|
|
+ resultData = uploadBaseService.upload(bean);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resultData = this.upload(bean);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (resultData.isSuccess()) {
|
|
|
|
|
+ // 组装百度编辑器格式
|
|
|
|
|
+ state = new EditorStateBean(true);
|
|
|
|
|
+ state.put("original", bean.getFileName());
|
|
|
|
|
+ state.put("size", bean.getFileSize());
|
|
|
|
|
+ state.put("title", FileNameUtil.getName(resultData.getData(String.class)));
|
|
|
|
|
+ state.put("type", "." + FileNameUtil.getSuffix(bean.getFileName()));
|
|
|
|
|
+ // 由于百度编辑器不是正常的uploadConfigBean,是无法正常通过getFileIdentifier获取到文件标识的,所以在这里做一个容错处理
|
|
|
|
|
+ state.put("fileIdentifier", bean.getFileIdentifier());
|
|
|
|
|
+ // 判断是否有contentPath
|
|
|
|
|
+ String contextPath = BasicUtil.getContextPath();
|
|
|
|
|
+ String filePath = resultData.getData(String.class);
|
|
|
|
|
+ if (StringUtils.isNotBlank(filePath) && !filePath.startsWith("http")) {
|
|
|
|
|
+ filePath = (contextPath.equals("/") ? "" : contextPath) + filePath;
|
|
|
}
|
|
}
|
|
|
- jsonMap.put("list", list);
|
|
|
|
|
|
|
+ state.put("url", filePath);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ state = new EditorStateBean(false, resultData.getMsg());
|
|
|
}
|
|
}
|
|
|
- return JSONUtil.toJsonStr(jsonMap);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|