ソースを参照

fix:修复链接文章的附件无法下载问题

lifei6671 6 年 前
コミット
34487947ba
1 ファイル変更5 行追加3 行削除
  1. 5 3
      controllers/BlogController.go

+ 5 - 3
controllers/BlogController.go

@@ -632,16 +632,18 @@ func (c *BlogController) Download() {
 	attachment, err := models.NewAttachment().Find(attachId)
 
 	if err != nil {
-		beego.Error("DownloadAttachment => ", err)
 		if err == orm.ErrNoRows {
 			c.ShowErrorPage(404, "附件不存在")
 		} else {
+			beego.Error("查询附件时出现异常 -> ", err)
 			c.ShowErrorPage(500, "查询附件时出现异常")
 		}
 	}
-	if blog.BlogType == 1 && attachment.BookId != blog.BookId && attachment.DocumentId != blog.DocumentId {
+
+	//如果是链接的文章,需要校验文档ID是否一致,如果不是,需要保证附件的项目ID为0且文档的ID等于博文ID
+	if blog.BlogType == 1 && attachment.DocumentId != blog.DocumentId {
 		c.ShowErrorPage(404, "附件不存在")
-	} else if attachment.BookId != 0 || attachment.DocumentId != blogId {
+	} else if blog.BlogType != 1 && (attachment.BookId != 0 || attachment.DocumentId != blogId ) {
 		c.ShowErrorPage(404, "附件不存在")
 	}