文件返回header带上文件长度,文章发布和撤下不修改原来的发布时间
This commit is contained in:
parent
eeec5453ae
commit
1de4a531b2
|
@ -12,7 +12,7 @@ const REDIS_BLOG_DIARY_LATEST string = "blog:diary:latest"
|
||||||
|
|
||||||
//文件相关Key常量
|
//文件相关Key常量
|
||||||
const REDIS_FILE string = "blog:file:"
|
const REDIS_FILE string = "blog:file:"
|
||||||
const REDIS_FILE_BYTES string = "blog:file:bytes"
|
const REDIS_FILE_BYTES string = "blog:file:bytes:"
|
||||||
|
|
||||||
//文本相关Key常量
|
//文本相关Key常量
|
||||||
const REDIS_BLOG_CONTENT string = "blog:content:"
|
const REDIS_BLOG_CONTENT string = "blog:content:"
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"blog/internal/service"
|
"blog/internal/service"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12/mvc"
|
"github.com/kataras/iris/v12/mvc"
|
||||||
|
@ -22,6 +23,7 @@ func (ctrl *FileController) ViewFile() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctrl.Ctx.Header("Content-Disposition", "attachment;filename="+url.QueryEscape(file.FileName))
|
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)
|
ctrl.Ctx.Write(file.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import "encoding/json"
|
||||||
type CommonFiles struct {
|
type CommonFiles struct {
|
||||||
Id string `json:"id" gorm:"primary_key"`
|
Id string `json:"id" gorm:"primary_key"`
|
||||||
FileName string `json:"fileName"`
|
FileName string `json:"fileName"`
|
||||||
|
FileSize int64 `json:"fileSize"`
|
||||||
Data []byte `json:"-"`
|
Data []byte `json:"-"`
|
||||||
Sort int32 `json:"sort"`
|
Sort int32 `json:"sort"`
|
||||||
CreateBy string `json:"-"`
|
CreateBy string `json:"-"`
|
||||||
|
|
|
@ -141,7 +141,9 @@ func (*articleService) PublishArticle(id string) error {
|
||||||
return errors.New("发布失败,文章状态不是起草状态,无法发布")
|
return errors.New("发布失败,文章状态不是起草状态,无法发布")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if article.PublishTime == 0 {
|
||||||
article.PublishTime = now
|
article.PublishTime = now
|
||||||
|
}
|
||||||
article.State = consts.ARTICLE_STATE_PUBLISH
|
article.State = consts.ARTICLE_STATE_PUBLISH
|
||||||
|
|
||||||
err = database.WGorm().Transaction(func(tx *gorm.DB) error {
|
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.State = consts.ARTICLE_STATE_DRAFT
|
||||||
article.PublishTime = -1
|
// article.PublishTime = -1
|
||||||
txErr = tx.Table("blog_articles").Updates(&article).Error
|
txErr = tx.Table("blog_articles").Updates(&article).Error
|
||||||
if txErr != nil {
|
if txErr != nil {
|
||||||
return errors.New("文章状态更新错误")
|
return errors.New("文章状态更新错误")
|
||||||
|
|
Loading…
Reference in New Issue