From fbad6529df4398009c490dfed5f768bb541becd6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BD=95=E6=96=87=E7=83=A8?= <1426317404@qq.com>
Date: Tue, 26 Nov 2024 07:41:38 +0000
Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbanner=E4=B8=8A=E4=BC=A0?=
=?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9A=84bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 何文烨 <1426317404@qq.com>
---
views/admin/banner/index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/views/admin/banner/index.html b/views/admin/banner/index.html
index 3ee726e..dc17826 100644
--- a/views/admin/banner/index.html
+++ b/views/admin/banner/index.html
@@ -230,8 +230,8 @@
handleRemove (file, fileList) {
},
handleUploadSuccess (response, file, fileList) {
- if (response && response.data) {
- this.modelForm.smallimg = '/' + response.data.path
+ if (response && response.location) {
+ this.modelForm.smallimg = '/' + response.location
}
},
handleImgPreview (file) {
--
Gitee
From 948d06170bd15f46aa4efe7cd91269c0ac3e691e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BD=95=E6=96=87=E7=83=A8?= <1426317404@qq.com>
Date: Wed, 27 Nov 2024 11:05:20 +0000
Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E4=BB=A5?=
=?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=AF=BB=E5=8F=96=E4=B8=80=E4=B8=AA=E6=9C=AC?=
=?UTF-8?q?=E5=9C=B0=E6=96=87=E7=AB=A0=E5=9B=BE=E7=89=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 何文烨 <1426317404@qq.com>
---
app/controller/admin/article.go | 38 +++++++++++++----------------
views/defaulted/article/detail.html | 3 +++
views/green/article/detail.html | 3 +++
views/home/article/detail.html | 3 +++
4 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/app/controller/admin/article.go b/app/controller/admin/article.go
index 3caa2b0..cf54b0a 100644
--- a/app/controller/admin/article.go
+++ b/app/controller/admin/article.go
@@ -87,11 +87,11 @@ func (b *Article) EditMd(c *gin.Context) {
response.HTML(c, "article/md", nil)
}
-// Insert 新增保存
func (b *Article) Insert(c *gin.Context) {
Article := &model.Article{}
Article.Username = c.GetString("current_user_name")
+ // Bind the incoming request data to the Article struct
if err := c.ShouldBind(&Article); err != nil {
c.JSON(400, gin.H{
"err": err.Error(),
@@ -99,41 +99,37 @@ func (b *Article) Insert(c *gin.Context) {
return
}
- // Article.Content = utils.RepImages(Article.Content)
- err := service.Article.Create(Article)
+ // Extract the first image URL from the content and store it in smallimg
+ Article.Smallimg = "\\" + extractImageURL(Article.Content)
+ // Create the article in the database
+ err := service.Article.Create(Article)
if err != nil {
logrus.Error("新增失败", err)
response.Fail(c, e.ErrorUpdate)
return
}
+ // Return the success response with the created article data
response.Success(c, Article)
}
-// Update 修改
-func (b *Article) Update(c *gin.Context) {
- Article := &model.Article{}
-
- if err := c.ShouldBind(&Article); err != nil {
- c.JSON(400, gin.H{
- "err": err.Error(),
- })
- return
- }
-
- id := strconv.Itoa(Article.Id)
- err := service.Article.Update(id, Article)
+// extractImageURL 用于提取 content 中的图片路径
+func extractImageURL(content string) string {
+ // 正则表达式匹配 img 标签中的 src 属性
+ re := regexp.MustCompile(`
]*src=["']([^"']+)["'][^>]*>`)
+ matches := re.FindStringSubmatch(content)
- if err != nil {
- logrus.Error("修改失败", err)
- response.Fail(c, e.ErrorUpdate)
- return
+ if len(matches) > 1 {
+ // 返回第一个图片的 src 地址
+ return matches[1]
}
- response.Success(c, Article)
+ // 如果没有找到图片路径,返回空字符串
+ return ""
}
+
// Destroy 删除
func (b *Article) Destroy(c *gin.Context) {
id := c.PostForm("id")
diff --git a/views/defaulted/article/detail.html b/views/defaulted/article/detail.html
index 6946730..513ffb9 100644
--- a/views/defaulted/article/detail.html
+++ b/views/defaulted/article/detail.html
@@ -41,6 +41,9 @@
{{ data.article.Content | safe }}
+ {% if data.article.Smallimg %}
+

+ {% endif %}
diff --git a/views/green/article/detail.html b/views/green/article/detail.html
index 34cd8de..bb56dd6 100644
--- a/views/green/article/detail.html
+++ b/views/green/article/detail.html
@@ -78,6 +78,9 @@
{{ data.article.Content | safe }}
+ {% if data.article.Smallimg %}
+

+ {% endif %}
diff --git a/views/home/article/detail.html b/views/home/article/detail.html
index 23bb1fa..d6c6de2 100644
--- a/views/home/article/detail.html
+++ b/views/home/article/detail.html
@@ -17,6 +17,9 @@
{{ data.article.Content | safe }}
+ {% if data.article.Smallimg %}
+

+ {% endif %}
--
Gitee
From a60d45c511c407f00ba71378ac8f6435bfc2ccd0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BD=95=E6=96=87=E7=83=A8?= <1426317404@qq.com>
Date: Thu, 28 Nov 2024 08:10:04 +0000
Subject: [PATCH 3/4] =?UTF-8?q?=E5=AE=8C=E5=85=A8=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E5=9B=BE=E7=89=87=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 何文烨 <1426317404@qq.com>
---
app/controller/admin/upload.go | 2 +-
views/defaulted/article/detail.html | 3 ---
views/green/article/detail.html | 3 ---
views/home/article/detail.html | 3 ---
4 files changed, 1 insertion(+), 10 deletions(-)
diff --git a/app/controller/admin/upload.go b/app/controller/admin/upload.go
index 5120369..dffe766 100644
--- a/app/controller/admin/upload.go
+++ b/app/controller/admin/upload.go
@@ -78,7 +78,7 @@ func uploadLocal(c *gin.Context, file *multipart.FileHeader) (string, error) {
if err != nil {
return "", err
}
- return filePath, nil
+ return "\\"+filePath, nil
}
func uploadOss(file *multipart.FileHeader) (bool, string) {
diff --git a/views/defaulted/article/detail.html b/views/defaulted/article/detail.html
index 513ffb9..6946730 100644
--- a/views/defaulted/article/detail.html
+++ b/views/defaulted/article/detail.html
@@ -41,9 +41,6 @@
{{ data.article.Content | safe }}
- {% if data.article.Smallimg %}
-

- {% endif %}
diff --git a/views/green/article/detail.html b/views/green/article/detail.html
index bb56dd6..34cd8de 100644
--- a/views/green/article/detail.html
+++ b/views/green/article/detail.html
@@ -78,9 +78,6 @@
{{ data.article.Content | safe }}
- {% if data.article.Smallimg %}
-

- {% endif %}
diff --git a/views/home/article/detail.html b/views/home/article/detail.html
index d6c6de2..23bb1fa 100644
--- a/views/home/article/detail.html
+++ b/views/home/article/detail.html
@@ -17,9 +17,6 @@
{{ data.article.Content | safe }}
- {% if data.article.Smallimg %}
-

- {% endif %}
--
Gitee
From 784b8456d36c9eabd5d004da1c06d77aa5c5c36f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BD=95=E6=96=87=E7=83=A8?= <1426317404@qq.com>
Date: Thu, 28 Nov 2024 08:27:01 +0000
Subject: [PATCH 4/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?=
=?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 何文烨 <1426317404@qq.com>
---
app/controller/admin/article.go | 34 +++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/app/controller/admin/article.go b/app/controller/admin/article.go
index cf54b0a..02f2f9d 100644
--- a/app/controller/admin/article.go
+++ b/app/controller/admin/article.go
@@ -87,6 +87,8 @@ func (b *Article) EditMd(c *gin.Context) {
response.HTML(c, "article/md", nil)
}
+// Insert 新增保存
+// Insert 新增保存
func (b *Article) Insert(c *gin.Context) {
Article := &model.Article{}
Article.Username = c.GetString("current_user_name")
@@ -99,8 +101,7 @@ func (b *Article) Insert(c *gin.Context) {
return
}
- // Extract the first image URL from the content and store it in smallimg
- Article.Smallimg = "\\" + extractImageURL(Article.Content)
+ // Extract all image URLs from the content and store them in smallimg, separated by "|"
// Create the article in the database
err := service.Article.Create(Article)
@@ -114,22 +115,31 @@ func (b *Article) Insert(c *gin.Context) {
response.Success(c, Article)
}
-// extractImageURL 用于提取 content 中的图片路径
-func extractImageURL(content string) string {
- // 正则表达式匹配 img 标签中的 src 属性
- re := regexp.MustCompile(`
![]()
]*src=["']([^"']+)["'][^>]*>`)
- matches := re.FindStringSubmatch(content)
+// Update 修改
+func (b *Article) Update(c *gin.Context) {
+ Article := &model.Article{}
+
+ if err := c.ShouldBind(&Article); err != nil {
+ c.JSON(400, gin.H{
+ "err": err.Error(),
+ })
+ return
+ }
+
+ id := strconv.Itoa(Article.Id)
+ err := service.Article.Update(id, Article)
- if len(matches) > 1 {
- // 返回第一个图片的 src 地址
- return matches[1]
+ if err != nil {
+ logrus.Error("修改失败", err)
+ response.Fail(c, e.ErrorUpdate)
+ return
}
- // 如果没有找到图片路径,返回空字符串
- return ""
+ response.Success(c, Article)
}
+
// Destroy 删除
func (b *Article) Destroy(c *gin.Context) {
id := c.PostForm("id")
--
Gitee