فهرست منبع

fix:代码同步

msdev 5 ماه پیش
والد
کامیت
ba0f9d174c

+ 45 - 8
src/main/java/net/mingsoft/cms/action/BaseAction.java

@@ -23,14 +23,21 @@
 package net.mingsoft.cms.action;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.file.FileNameUtil;
+import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.StrUtil;
 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 net.mingsoft.base.constant.Const;
+import net.mingsoft.base.entity.ResultData;
 import net.mingsoft.base.exception.BusinessException;
 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.util.BasicUtil;
 import net.mingsoft.config.MSProperties;
@@ -47,7 +54,7 @@ import java.util.MissingResourceException;
  * @Author: 铭飞开源团队--huise
  * @Date: 2019/8/9 20:47
  */
-public class BaseAction extends net.mingsoft.basic.action.BaseAction{
+public class BaseAction extends BaseFileAction {
     /**
      * 读取国际化资源文件(没有占位符号的),优先模块对应的资源文件,如果模块资源文件找不到就会优先基础层
      * @param key 国际化文件key
@@ -90,10 +97,16 @@ public class BaseAction extends net.mingsoft.basic.action.BaseAction{
      */
     public String exec(HttpServletRequest request, MultipartFile upfile, Map execFileConfigMap, String version){
         String uploadFolderPath = MSProperties.upload.path;
+        String uploadMapping = MSProperties.upload.mapping;
 
-        String configRootPath = ConfigUtil.getString("文件上传配置", "uploadPath", "");
-        uploadFolderPath = StringUtils.isBlank(configRootPath) ? uploadFolderPath : configRootPath;
-        String rootPath = BasicUtil.getRealPath(uploadFolderPath);
+        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);
 
         Map execConfigMap = new HashMap();
         execConfigMap.putAll(execFileConfigMap);
@@ -103,7 +116,11 @@ public class BaseAction extends net.mingsoft.basic.action.BaseAction{
         String datePath = DateUtil.format(new Date(), "yyyyMMdd");
 
         // /appId/editor/yyyyMMdd/{time}
-        String filePathFormat = "/".concat(app.getAppId()).concat("/editor/").concat(datePath).concat("/").concat("{time}");
+        String filePath = "/".concat(app.getAppId()).concat("/editor/").concat(datePath).concat("/");
+
+        String filePathFormat = filePath.concat("{time}");
+
+
 
         execConfigMap.put("imagePathFormat", filePathFormat);
         execConfigMap.put("filePathFormat", filePathFormat);
@@ -116,20 +133,40 @@ public class BaseAction extends net.mingsoft.basic.action.BaseAction{
 
         // 文件主名称不允许为空
         if (upfile != null){
+            State state = null;
             String upFileMainName = FileNameUtil.mainName(upfile.getOriginalFilename());
             if (StringUtils.isBlank(upFileMainName)){
-                throw new BusinessException(getResString("err.error",getResString("file.name")));
+                return new BaseState(false, getResString("err.error",getResString("file.name"))).toJSONString();
+            }
+            UploadConfigBean configBean = new UploadConfigBean(filePath, upfile, null, true);
+            try {
+                ResultData resultData = this.upload(configBean);
+                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()));
+                    state.putInfo("url", resultData.getData(String.class));
+                } else {
+                    state = new BaseState(false, resultData.getMsg());
+                }
+                return  state.toJSONString();
+            } catch (Exception e) {
+                e.printStackTrace();
+                return new BaseState(false, 500).toJSONString();
             }
         }
 
         //过滤非法上传路径
         if (execConfig != null && (execConfig.contains("../") || execConfig.contains("..\\"))) {
-            throw new BusinessException(BundleUtil.getString(Const.RESOURCES,"err.error",BundleUtil.getString(net.mingsoft.basic.constant.Const.RESOURCES,"file.path")));
+            return new BaseState(false, BundleUtil.getString(Const.RESOURCES,"err.error",BundleUtil.getString(net.mingsoft.basic.constant.Const.RESOURCES,"file.path"))).toJSONString();
         }
         UeditorActionEnter actionEnter = new UeditorActionEnter(upfile,request, rootPath, execConfig, BasicUtil.getRealPath(""), BasicUtil.getRealPath(StrUtil.format("static/plugins/ueditor/{}/config.json",version)));
         String result = actionEnter.exec();
         Map jsonMap = JSONUtil.toBean(result,Map.class);
-        jsonMap.put("url","/".concat(uploadFolderPath).concat(jsonMap.get("url")+""));
+        jsonMap.put("url","/".concat(uploadMapping.replaceAll("/([\\s\\S]*)/\\*\\*",  "$1")).concat(jsonMap.get("url")+""));
         return JSONUtil.toJsonStr(jsonMap);
 
 

+ 4 - 24
src/main/java/net/mingsoft/cms/action/EditorAction.java

@@ -1,25 +1,5 @@
-/**
- * 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.action;
+
 import cn.hutool.core.map.MapUtil;
 import io.swagger.v3.oas.annotations.Hidden;
 import jakarta.annotation.Resource;
@@ -70,9 +50,9 @@ public class EditorAction extends BaseAction{
             map.put("fileMaxSize", MapUtil.getLong(uploadConfig,"fileSize") * 1000);
         }else {
             // 控制大小
-            map.put("imageMaxSize", maxFileSize);
-            map.put("videoMaxSize", maxFileSize);
-            map.put("fileMaxSize", maxFileSize);
+            map.put("imageMaxSize", maxFileSize * 1000);
+            map.put("videoMaxSize", maxFileSize * 1000);
+            map.put("fileMaxSize", maxFileSize * 1000);
         }
 
         return exec(request,upfile,map,version);

+ 4 - 5
src/main/java/net/mingsoft/cms/action/web/ContentAction.java

@@ -87,7 +87,7 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
 	 */
 	@Operation(summary = "查询文章列表接口")
 	@Parameters({
-			@Parameter(name = "typeid", description = "所属栏目", required =true, in= ParameterIn.QUERY),
+			@Parameter(name = "typeid", description = "所属栏目", required =false, in= ParameterIn.QUERY),
 			@Parameter(name = "pageNo", description = "页码", required =false, in= ParameterIn.QUERY),
 			@Parameter(name = "size", description = "一页显示数量", required =false, in= ParameterIn.QUERY),
 			@Parameter(name = "orderby", description = "排序", required =false, in= ParameterIn.QUERY),
@@ -98,13 +98,12 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
 		//会将请求参数全部转换map
 		Map map = BasicUtil.assemblyRequestMap();
 		String typeid = (String) map.get("typeid");
-		if (StrUtil.isBlank(typeid)){
-			return ResultData.build().error(getResString("err.empty", this.getResString("content.category.id")));
-		}
 		ContentBean content = new ContentBean();
+		if (StrUtil.isNotBlank(typeid)){
+			content.setCategoryId(typeid);
+		}
 		content.setCategoryType(CategoryTypeEnum.LIST.toString());
 		content.setContentDisplay("0");
-		content.setCategoryId(typeid);
 		List<CategoryBean> articleList = contentBiz.queryIdsByCategoryIdForParser(content);
 		PageBean page = new PageBean();
 		List filedStr = new ArrayList<>();

+ 3 - 1
src/main/java/net/mingsoft/cms/action/web/EditorAction.java

@@ -22,6 +22,8 @@
 
 
 
+
+
 package net.mingsoft.cms.action.web;
 
 import cn.hutool.core.map.MapUtil;
@@ -65,7 +67,7 @@ public class EditorAction extends BaseAction {
         boolean enableWeb = MSProperties.upload.enableWeb;
 
         Map uploadConfig = ConfigUtil.getMap("文件上传配置");
-        long maxFileSize = msProperties.getUpload().getMultipart().getMaxFileSize();
+        long maxFileSize = msProperties.getUpload().getMultipart().getMaxFileSize() * 1000;
         // 兼容其他版本的上传配置
         if (MapUtil.isNotEmpty(uploadConfig)){
             enableWeb = Boolean.parseBoolean(String.valueOf(uploadConfig.get("uploadEnable")));