From 1de4a531b21a1def08c859e7317f5124f1e78348 Mon Sep 17 00:00:00 2001 From: sysnix <535420543@qq.com> Date: Mon, 25 Sep 2023 04:36:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=BF=94=E5=9B=9Eheader?= =?UTF-8?q?=E5=B8=A6=E4=B8=8A=E6=96=87=E4=BB=B6=E9=95=BF=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=8F=91=E5=B8=83=E5=92=8C=E6=92=A4=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E4=BF=AE=E6=94=B9=E5=8E=9F=E6=9D=A5=E7=9A=84=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/consts/RedisConst.go | 2 +- internal/controller/FileController.go | 2 ++ internal/model/vo/CommonFiles.go | 1 + internal/service/ArticleService.go | 6 ++++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/consts/RedisConst.go b/internal/consts/RedisConst.go index d7e9db6..1d26993 100644 --- a/internal/consts/RedisConst.go +++ b/internal/consts/RedisConst.go @@ -12,7 +12,7 @@ const REDIS_BLOG_DIARY_LATEST string = "blog:diary:latest" //文件相关Key常量 const REDIS_FILE string = "blog:file:" -const REDIS_FILE_BYTES string = "blog:file:bytes" +const REDIS_FILE_BYTES string = "blog:file:bytes:" //文本相关Key常量 const REDIS_BLOG_CONTENT string = "blog:content:" diff --git a/internal/controller/FileController.go b/internal/controller/FileController.go index 259a670..e88fc1f 100644 --- a/internal/controller/FileController.go +++ b/internal/controller/FileController.go @@ -4,6 +4,7 @@ import ( "blog/internal/service" "net/http" "net/url" + "strconv" "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/mvc" @@ -22,6 +23,7 @@ func (ctrl *FileController) ViewFile() { return } ctrl.Ctx.Header("Content-Disposition", "attachment;filename="+url.QueryEscape(file.FileName)) + ctrl.Ctx.Header("Content-Length", strconv.FormatInt(file.FileSize, 10)) ctrl.Ctx.Write(file.Data) } diff --git a/internal/model/vo/CommonFiles.go b/internal/model/vo/CommonFiles.go index 56890fc..513401d 100644 --- a/internal/model/vo/CommonFiles.go +++ b/internal/model/vo/CommonFiles.go @@ -5,6 +5,7 @@ import "encoding/json" type CommonFiles struct { Id string `json:"id" gorm:"primary_key"` FileName string `json:"fileName"` + FileSize int64 `json:"fileSize"` Data []byte `json:"-"` Sort int32 `json:"sort"` CreateBy string `json:"-"` diff --git a/internal/service/ArticleService.go b/internal/service/ArticleService.go index 8552de3..84a6ebc 100644 --- a/internal/service/ArticleService.go +++ b/internal/service/ArticleService.go @@ -141,7 +141,9 @@ func (*articleService) PublishArticle(id string) error { return errors.New("发布失败,文章状态不是起草状态,无法发布") } - article.PublishTime = now + if article.PublishTime == 0 { + article.PublishTime = now + } article.State = consts.ARTICLE_STATE_PUBLISH err = database.WGorm().Transaction(func(tx *gorm.DB) error { @@ -201,7 +203,7 @@ func (*articleService) UnPublishArticle(id string) error { } article.State = consts.ARTICLE_STATE_DRAFT - article.PublishTime = -1 + // article.PublishTime = -1 txErr = tx.Table("blog_articles").Updates(&article).Error if txErr != nil { return errors.New("文章状态更新错误")