From 95ef76d6440a5363c0b7981b1333f82f9345322d Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 07 Jul 2022 15:15:56 +0800
Subject: [PATCH] fix template upload

---
 src/main/java/com/xcong/farmer/cms/core/template/Configuration.java                        |   17 ++++++++++-------
 src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java |    9 +++++----
 src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java                |    4 ++--
 src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java                                 |    9 +++++++++
 src/main/resources/application-test.yml                                                    |   10 +++++-----
 src/main/java/com/xcong/farmer/cms/configurations/CmsConfig.java                           |    2 +-
 src/main/resources/application.yml                                                         |    4 ++--
 7 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/xcong/farmer/cms/configurations/CmsConfig.java b/src/main/java/com/xcong/farmer/cms/configurations/CmsConfig.java
index 1e7697f..8b5873f 100644
--- a/src/main/java/com/xcong/farmer/cms/configurations/CmsConfig.java
+++ b/src/main/java/com/xcong/farmer/cms/configurations/CmsConfig.java
@@ -23,7 +23,7 @@
     @Bean
     public TemplateConfiguration templateConfiguration() {
         log.info("CMS管理系统");
-        TemplateConfiguration cfg = new TemplateConfiguration(cmsProperties.getTemplatePath(), cmsProperties.getStaticPath(), cmsProperties.getOutputPath());
+        TemplateConfiguration cfg = new TemplateConfiguration(cmsProperties.getTemplatePath(), cmsProperties.getStaticPath(), cmsProperties.getOutputPath(), cmsProperties.getBaseUrl(), cmsProperties.getStaticUrl());
         TemplateLoader loader = new TemplateLoader(cfg);
         cfg.templateLoader(loader);
         return cfg;
diff --git a/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java b/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
index b11eae9..38c8fcc 100644
--- a/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
+++ b/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
@@ -2,6 +2,7 @@
 
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.xcong.farmer.cms.core.handler.DataParserHandler;
 import com.xcong.farmer.cms.core.tag.TagsEnum;
@@ -77,6 +78,14 @@
         }
 
         this.element.empty();
+
+        // 设置img的链接访问
+        if ("img".equals(this.element.tagName())) {
+            String src = this.element.attr("src");
+            if (StrUtil.isNotBlank(STATIC_URL)) {
+                this.element.attr("src", STATIC_URL + src);
+            }
+        }
         Attributes attributes = this.element.attributes();
         if (attributes.isEmpty()) {
             return;
diff --git a/src/main/java/com/xcong/farmer/cms/core/template/Configuration.java b/src/main/java/com/xcong/farmer/cms/core/template/Configuration.java
index f2c97b0..897392b 100644
--- a/src/main/java/com/xcong/farmer/cms/core/template/Configuration.java
+++ b/src/main/java/com/xcong/farmer/cms/core/template/Configuration.java
@@ -6,17 +6,20 @@
 
 public abstract class Configuration {
 
-    public String staticPath;
-    public String templatePath;
-    public String outputPath;
+    protected static String BASE_URL;
+    protected static String STATIC_URL;
+    protected static String staticPath;
+    protected static String templatePath;
+    protected static String outputPath;
 
     public Configuration() {
     }
 
-    public Configuration(String templatePath, String staticPath, String outputPath) {
-        this.staticPath = staticPath;
-        this.templatePath = templatePath;
-        this.outputPath = outputPath;
+    public Configuration(String templatePath, String staticPath, String outputPath, String baseUrl, String staticUrl) {
+        Configuration.staticPath = staticPath;
+        Configuration.templatePath = templatePath;
+        Configuration.outputPath = outputPath;
+        Configuration.BASE_URL = baseUrl;
     }
 
     public static Map<String, String> templateCode = new HashMap<>();
diff --git a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
index b3f748a..dba37a4 100644
--- a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
+++ b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
@@ -18,8 +18,8 @@
 
     private TemplateLoader templateLoader;
 
-    public TemplateConfiguration(String templatePath, String staticPath, String outputPath) {
-        super(templatePath, staticPath, outputPath);
+    public TemplateConfiguration(String templatePath, String staticPath, String outputPath, String baseUrl, String staticUrl) {
+        super(templatePath, staticPath, outputPath, baseUrl, staticUrl);
     }
 
     public void templateLoader(TemplateLoader templateLoader) {
diff --git a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
index e21b47d..58c80e2 100644
--- a/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
+++ b/src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
@@ -45,14 +45,14 @@
 public class CmsTemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTemplateEntity> implements ICmsTemplateService {
 
     @Autowired
-    private TemplateConfiguration cfg;
+    private CmsProperties properties;
 
     private List<String> fileSuffix = Arrays.asList(".zip", ".html");
 
     @Override
     public void updateTemplate(MultipartFile upload) {
-        String templatePath = cfg.templatePath;
-        String staticPath = cfg.staticPath;
+        String templatePath = properties.getTemplatePath();
+        String staticPath = properties.getStaticPath();
 
         String filename = upload.getOriginalFilename();
         String suffix = filename.substring(filename.lastIndexOf("."));
@@ -78,6 +78,7 @@
 
                 for (File templateFile : files) {
                     if (!templateFile.isFile()) {
+                        FileUtil.move(templateFile, new File(FileUtils.path(staticPath, templateFile.getName())), true);
                         continue;
                     }
 
@@ -86,7 +87,7 @@
                     }
 
                     String name = templateFile.getName();
-                    if (!name.endsWith(".list.html") && !name.endsWith(".article.html") && !name.endsWith(".index.html")) {
+                    if (!name.endsWith(".list.html") && !name.endsWith(".article.html") && !name.endsWith("index.html")) {
                         continue;
                     }
 
diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml
index 02efd62..82cd886 100644
--- a/src/main/resources/application-test.yml
+++ b/src/main/resources/application-test.yml
@@ -93,9 +93,9 @@
     path: /home/javaweb/webresource/uploadeFile/image/
 
 cms:
-  base-url: http://localhost
-  static-url: http://localhost
-  template-path: /Users/helius/Desktop/template
-  static-path:
-  output-path: /Users/helius/Desktop/web/output
+  base-url: http://120.27.238.55:8000/cms/output
+  static-url: http://120.27.238.55:8000/cms/static
+  template-path: /home/javaweb/webresource/cms/template
+  static-path: /home/javaweb/webresource/cms/static
+  output-path: /home/javaweb/webresource/cms/output
 
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index f9fee05..e2ebc6d 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -99,7 +99,7 @@
 cms:
   base-url: http://localhost
   static-url: http://localhost
-  template-path: /Users/helius/Desktop/template
-  static-path:
+  template-path: /Users/helius/Desktop/template/upload
+  static-path: /Users/helius/Desktop/static
   output-path: /Users/helius/Desktop/web/output
 

--
Gitblit v1.9.1