mingsoft 4 ماه پیش
والد
کامیت
d3fa88d592

+ 4 - 4
pom.xml

@@ -21,22 +21,22 @@
         <dependency>
             <groupId>net.mingsoft</groupId>
             <artifactId>ms-base</artifactId>
-            <version>3.0.0.3</version>
+            <version>3.0.1</version>
         </dependency>
         <dependency>
             <groupId>net.mingsoft</groupId>
             <artifactId>ms-basic</artifactId>
-            <version>3.0.0.3.1</version>
+            <version>3.0.1</version>
         </dependency>
         <dependency>
             <groupId>net.mingsoft</groupId>
             <artifactId>ms-mdiy</artifactId>
-            <version>3.0.0.3</version>
+            <version>3.0.1</version>
         </dependency>
         <dependency>
             <groupId>net.mingsoft</groupId>
             <artifactId>store-client</artifactId>
-            <version>3.0.0.3</version>
+            <version>3.0.1</version>
         </dependency>
         <dependency>
             <groupId>com.github.oshi</groupId>

+ 44 - 7
src/main/java/net/mingsoft/cms/action/BaseAction.java

@@ -39,12 +39,17 @@ import net.mingsoft.base.util.BundleUtil;
 import net.mingsoft.basic.action.BaseFileAction;
 import net.mingsoft.basic.bean.UploadConfigBean;
 import net.mingsoft.basic.entity.AppEntity;
+import net.mingsoft.basic.service.IUploadBaseService;
 import net.mingsoft.basic.util.BasicUtil;
+import net.mingsoft.basic.util.SpringUtil;
 import net.mingsoft.config.MSProperties;
 import net.mingsoft.mdiy.util.ConfigUtil;
+import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -116,9 +121,9 @@ public class BaseAction extends BaseFileAction {
         String datePath = DateUtil.format(new Date(), "yyyyMMdd");
 
         // /appId/editor/yyyyMMdd/{time}
-        String filePath = "/".concat(app.getAppId()).concat("/editor/").concat(datePath).concat("/");
+        String uploadPath = "/".concat(app.getAppId()).concat("/editor/").concat(datePath).concat("/");
 
-        String filePathFormat = filePath.concat("{time}");
+        String filePathFormat = uploadPath.concat("{time}");
 
 
 
@@ -131,16 +136,40 @@ public class BaseAction extends BaseFileAction {
 
         String execConfig = JSONUtil.toJsonStr(execConfigMap);
 
-        // 文件主名称不允许为空
+        // 如果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();
             }
-            UploadConfigBean configBean = new UploadConfigBean(filePath, upfile, null, true);
+            // 组装uploadConfigBean上传使用
+            UploadConfigBean bean = new UploadConfigBean(uploadPath, upfile, null, true);
+            bean.setFileSize(upfile.getSize());
+            bean.setFileName(upfile.getOriginalFilename());
             try {
-                ResultData resultData = this.upload(configBean);
+                // 判断是依赖ms-file插件
+                String type = ConfigUtil.getString("存储设置", "storeSelect");
+                IUploadBaseService uploadBaseService = null;
+                if (StringUtils.isNotBlank(type)) {
+                    // 单个文件上传计算下各个参数值避免重复上传
+                    if (StringUtils.isBlank(bean.getFileIdentifier())){
+                        try {
+                            bean.setFileIdentifier(String.valueOf(Hex.encodeHex(MessageDigest.getInstance("MD5").digest(bean.getFile().getBytes()))));
+                        } catch (NoSuchAlgorithmException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                    //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);
@@ -148,11 +177,19 @@ public class BaseAction extends BaseFileAction {
                     state.putInfo("size", upfile.getSize());
                     state.putInfo("title", FileNameUtil.getName(resultData.getData(String.class)));
                     state.putInfo("type", "." + FileNameUtil.getSuffix(upfile.getOriginalFilename()));
-                    state.putInfo("url", resultData.getData(String.class));
+                    // 由于百度编辑器不是正常的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();
+                return state.toJSONString();
             } catch (Exception e) {
                 e.printStackTrace();
                 return new BaseState(false, 500).toJSONString();

+ 109 - 0
src/main/java/net/mingsoft/cms/aop/EditorFileVerifyAop.java

@@ -0,0 +1,109 @@
+/**
+ * The MIT License (MIT)
+ * Copyright (c) 2012-present 铭软科技(mingsoft.net)
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * 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,
+ * subject to the following conditions:
+ * <p>
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ * <p>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package net.mingsoft.cms.aop;
+
+import com.baidu.ueditor.define.BaseState;
+import net.mingsoft.base.entity.ResultData;
+import net.mingsoft.basic.aop.FileVerifyAop;
+import net.mingsoft.basic.bean.UploadConfigBean;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * @author 铭软开发团队
+ * @ClassName: EditorFileVerifyAop
+ * @Description: 检测编辑器上传的文件是否合法
+ * @date 2025年6月12日15:14:17
+ */
+@Component
+@Aspect
+public class EditorFileVerifyAop extends FileVerifyAop {
+
+    /**
+     * 切入点
+     */
+    @Pointcut()
+    public void uploadPointCut(){}
+
+    /**
+     * 后台上传文件的时候,将验证zip里的文件
+     * @param joinPoint
+     * @return
+     * @throws Throwable
+     */
+    @Around("execution(* net.mingsoft.cms.action.EditorAction.editor(..)) ")
+    public Object uploadAop(ProceedingJoinPoint joinPoint) throws Throwable {
+        Object[] args = joinPoint.getArgs();
+        MultipartFile file = null;
+        // TODO: 2025/6/12 通过getType无法获取file文件信息,所以改成这个方法获取文件信息
+        for (Object arg : args) {
+            if (arg instanceof MultipartFile) {
+                file = (MultipartFile) arg;
+            }
+        }
+        // 如果没有文件,可能是获取配置文件时,直接返回
+        if (file == null) {
+            return joinPoint.proceed();
+        }
+        UploadConfigBean bean = new UploadConfigBean();
+        bean.setFile(file);
+        ResultData resultData = prepareUpload(bean,false);
+        if (resultData.isSuccess()) {
+            return joinPoint.proceed();
+        }
+        return new BaseState(false, resultData.getMsg()).toString();
+    }
+
+    /**
+     * web上传文件的时候,将验证zip里的文件
+     * @param joinPoint
+     * @return
+     * @throws Throwable
+     */
+    @Around("execution(* net.mingsoft.cms.action.web.EditorAction.editor(..))")
+    public Object webUploadAop(ProceedingJoinPoint joinPoint) throws Throwable {
+        Object[] args = joinPoint.getArgs();
+        MultipartFile file = null;
+        // TODO: 2025/6/12 通过getType无法获取file文件信息,所以改成这个方法获取文件信息
+        for (Object arg : args) {
+            if (arg instanceof MultipartFile) {
+                file = (MultipartFile) arg;
+            }
+        }
+        // 如果没有文件,可能是获取配置文件时,直接返回
+        if (file == null) {
+            return joinPoint.proceed();
+        }
+        UploadConfigBean bean = new UploadConfigBean();
+        bean.setFile(file);
+        ResultData resultData = prepareUpload(bean,true);
+        if (resultData.isSuccess()) {
+            return joinPoint.proceed();
+        }
+        return new BaseState(false, resultData.getMsg()).toString();
+    }
+
+}

+ 24 - 4
src/main/webapp/WEB-INF/manager/cms/category/form.ftl

@@ -627,9 +627,25 @@
                         if (data.categoryFlag) {
                             data.categoryFlag = data.categoryFlag.join(',');
                         }
+                        //没有图片就直接为空,不能为[]
+                        if (data.categoryImg.length>0) {
+                            data.categoryImg.forEach(function (value) {
+                                value.url = value.url.replace(new RegExp('^'+ms.contextpath), "");
+                            });
+                            data.categoryImg = JSON.stringify(data.categoryImg);
+                        } else {
+                            data.categoryImg = '';
+                        }
+                        //没有图片就直接为空,不能为[]
+                        if (data.categoryIco.length>0) {
+                            data.categoryIco.forEach(function (value) {
+                                value.url = value.url.replace(new RegExp('^'+ms.contextpath), "");
+                            });
+                            data.categoryIco = JSON.stringify(data.categoryIco);
+                        } else {
+                            data.categoryIco = '';
+                        }
 
-                        data.categoryImg = JSON.stringify(data.categoryImg);
-                        data.categoryIco = JSON.stringify(data.categoryIco);
                         ms.http.post(url, data).then(function (res) {
                             if (res.result) {
 
@@ -695,7 +711,9 @@
                         if (res.data.categoryImg) {
                             res.data.categoryImg = JSON.parse(res.data.categoryImg);
                             res.data.categoryImg.forEach(function (value) {
-                                value.url = ms.contextpath + value.url;
+                                if(!value.url.startsWith("http://") && !value.url.startsWith("https://")) {
+                                    value.url = ms.contextpath + value.url;
+                                }
                             });
                         } else {
                             res.data.categoryImg = [];
@@ -703,7 +721,9 @@
                         if (res.data.categoryIco) {
                             res.data.categoryIco = JSON.parse(res.data.categoryIco);
                             res.data.categoryIco.forEach(function (value) {
-                                value.url = ms.contextpath + value.url;
+                                if(!value.url.startsWith("http://") && !value.url.startsWith("https://")) {
+                                    value.url = ms.contextpath + value.url;
+                                }
                             });
                         } else {
                             res.data.categoryIco = [];

+ 17 - 3
src/main/webapp/WEB-INF/manager/cms/content/form.ftl

@@ -517,7 +517,15 @@
                             data.contentTags = data.contentTags.join(',');
                         }
 
-                        data.contentImg = JSON.stringify(data.contentImg);
+                        if (data.contentImg.length>0) {
+                            data.contentImg.forEach(function (value) {
+                                value.url = value.url.replace(new RegExp('^'+ms.contextpath), "");
+                            });
+                            data.contentImg = JSON.stringify(data.contentImg);
+                        } else {
+                            data.contentImg = '';
+                        }
+
                         ms.http.post(url, data).then(function (res) {
                             if (res.result) {
                                 // 接受保存的文章id 避免新增单篇栏目保存不刷新时 再次修改造成多次保存
@@ -677,7 +685,9 @@
                         if (res.data.contentImg && res.data.contentImg != '') {
                             res.data.contentImg = JSON.parse(res.data.contentImg);
                             res.data.contentImg.forEach(function (value) {
-                                value.url = ms.contextpath + value.url;
+                                if(!value.url.startsWith("http://") && !value.url.startsWith("https://")) {
+                                    value.url = ms.contextpath + value.url;
+                                }
                             });
                         } else {
                             res.data.contentImg = [];
@@ -715,7 +725,9 @@
                             if (res.data.contentImg) {
                                 res.data.contentImg = JSON.parse(res.data.contentImg);
                                 res.data.contentImg.forEach(function (value) {
-                                    value.url = ms.contextpath + value.url;
+                                    if(!value.url.startsWith("http://") && !value.url.startsWith("https://")) {
+                                        value.url = ms.contextpath + value.url;
+                                    }
                                 });
                             } else {
                                 res.data.contentImg = [];
@@ -737,6 +749,8 @@
                                 that.categoryChangeEnabled = false;
                                 that.changeModel(category[0].id);
                             }
+                        }else {
+							that.changeModel(that.form.categoryId);
                         }
                     } else {
                         that.$notify({