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("文章状态更新错误")