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/3] =?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/3] =?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 @@