diff --git a/controllers/BlogController.go b/controllers/BlogController.go index 315eaa49..9735f3d6 100644 --- a/controllers/BlogController.go +++ b/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, "附件不存在") }