1
0

BlogController.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package controllers
  2. import (
  3. "strings"
  4. "github.com/lifei6671/mindoc/models"
  5. "time"
  6. "github.com/astaxie/beego"
  7. "github.com/lifei6671/mindoc/conf"
  8. "github.com/lifei6671/mindoc/utils/pagination"
  9. "strconv"
  10. "fmt"
  11. "os"
  12. "net/http"
  13. "path/filepath"
  14. "github.com/astaxie/beego/orm"
  15. "html/template"
  16. "encoding/json"
  17. "github.com/lifei6671/mindoc/utils"
  18. )
  19. type BlogController struct{
  20. BaseController
  21. }
  22. //文章阅读
  23. func (c *BlogController) Index() {
  24. c.Prepare()
  25. c.TplName = "blog/index.tpl"
  26. blogId,_ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  27. if blogId <= 0{
  28. c.ShowErrorPage(404,"页面不存在")
  29. }
  30. blogReadSession := fmt.Sprintf("blog:read:%d",blogId)
  31. blog,err := models.NewBlog().FindFromCache(blogId)
  32. if err != nil {
  33. c.ShowErrorPage(404,"文章不存在")
  34. }
  35. if c.Ctx.Input.IsPost() {
  36. password := c.GetString("password");
  37. if blog.BlogStatus == "password" && password != blog.Password {
  38. c.JsonResult(6001,"文章密码不正确")
  39. }else if blog.BlogStatus == "password" && password == blog.Password {
  40. //如果密码输入正确,则存入session中
  41. c.CruSession.Set(blogReadSession,blogId)
  42. c.JsonResult(0,"OK")
  43. }
  44. c.JsonResult(0,"OK")
  45. }else if blog.BlogStatus == "password" && (c.CruSession.Get(blogReadSession) == nil || (c.Member != nil && blog.MemberId != c.Member.MemberId && !c.Member.IsAdministrator() ) ){
  46. //如果不存在已输入密码的标记
  47. c.TplName = "blog/index_password.tpl"
  48. }
  49. //加载文章附件
  50. blog.LinkAttach();
  51. c.Data["Model"] = blog
  52. c.Data["Content"] = template.HTML(blog.BlogRelease)
  53. if blog.BlogExcerpt == "" {
  54. c.Data["Description"] = utils.AutoSummary(blog.BlogRelease,120)
  55. }else{
  56. c.Data["Description"] = blog.BlogExcerpt
  57. }
  58. if nextBlog,err := models.NewBlog().QueryNext(blogId);err == nil {
  59. c.Data["Next"] = nextBlog
  60. }
  61. if preBlog,err := models.NewBlog().QueryPrevious(blogId);err == nil {
  62. c.Data["Previous"] = preBlog
  63. }
  64. }
  65. //文章列表
  66. func (c *BlogController) List() {
  67. c.Prepare()
  68. c.TplName = "blog/list.tpl"
  69. pageIndex, _ := c.GetInt("page", 1)
  70. var blogList []*models.Blog
  71. var totalCount int
  72. var err error
  73. blogList,totalCount,err = models.NewBlog().FindToPager(pageIndex,conf.PageSize,0,"")
  74. if err != nil && err != orm.ErrNoRows {
  75. c.ShowErrorPage(500,err.Error())
  76. }
  77. if totalCount > 0 {
  78. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  79. c.Data["PageHtml"] = pager.HtmlPages()
  80. for _,blog := range blogList {
  81. //如果没有添加文章摘要,则自动提取
  82. if blog.BlogExcerpt == "" {
  83. blog.BlogExcerpt = utils.AutoSummary(blog.BlogRelease,120)
  84. }
  85. blog.Link()
  86. }
  87. } else {
  88. c.Data["PageHtml"] = ""
  89. }
  90. c.Data["Lists"] = blogList
  91. }
  92. //管理后台文章列表
  93. func (c *BlogController) ManageList() {
  94. c.Prepare()
  95. c.TplName = "blog/manage_list.tpl"
  96. pageIndex, _ := c.GetInt("page", 1)
  97. blogList,totalCount,err := models.NewBlog().FindToPager(pageIndex,conf.PageSize,c.Member.MemberId,"")
  98. if err != nil {
  99. c.ShowErrorPage(500,err.Error())
  100. }
  101. if totalCount > 0 {
  102. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  103. c.Data["PageHtml"] = pager.HtmlPages()
  104. } else {
  105. c.Data["PageHtml"] = ""
  106. }
  107. c.Data["ModelList"] = blogList
  108. }
  109. //文章设置
  110. func (c *BlogController) ManageSetting() {
  111. c.Prepare()
  112. c.TplName = "blog/manage_setting.tpl"
  113. //如果是post请求
  114. if c.Ctx.Input.IsPost() {
  115. blogId,_ := c.GetInt("id",0)
  116. blogTitle := c.GetString("title")
  117. blogIdentify := c.GetString("identify")
  118. orderIndex,_ := c.GetInt("order_index",0)
  119. blogType,_ := c.GetInt("blog_type",0)
  120. blogExcerpt := c.GetString("excerpt","")
  121. blogStatus := c.GetString("status","publish")
  122. blogPassword := c.GetString("password","")
  123. documentIdentify := strings.TrimSpace(c.GetString("documentIdentify"))
  124. bookIdentify := strings.TrimSpace(c.GetString("bookIdentify"))
  125. documentId := 0
  126. if blogTitle == "" {
  127. c.JsonResult(6001,"文章标题不能为空")
  128. }
  129. if strings.Count(blogExcerpt,"") > 500 {
  130. c.JsonResult(6008,"文章摘要必须小于500字符")
  131. }
  132. if blogStatus != "public" && blogStatus != "password" && blogStatus != "draft" {
  133. blogStatus = "public"
  134. }
  135. if blogStatus == "password" && blogPassword == "" {
  136. c.JsonResult(6010,"加密文章请设置密码")
  137. }
  138. if blogType != 0 && blogType != 1 {
  139. c.JsonResult(6005,"未知的文章类型")
  140. }
  141. if strings.Count(blogTitle,"") > 200 {
  142. c.JsonResult(6002,"文章标题不能大于200个字符")
  143. }
  144. //如果是关联文章,需要同步关联的文档
  145. if blogType == 1 {
  146. book,err := models.NewBook().FindByIdentify(bookIdentify)
  147. if err != nil {
  148. c.JsonResult(6011,"关联文档的项目不存在")
  149. }
  150. doc,err := models.NewDocument().FindByIdentityFirst(documentIdentify,book.BookId)
  151. if err != nil {
  152. c.JsonResult(6003,"查询关联项目文档时出错")
  153. }
  154. documentId = doc.DocumentId
  155. // 如果不是超级管理员,则校验权限
  156. if !c.Member.IsAdministrator() {
  157. bookResult, err := models.NewBookResult().FindByIdentify(book.Identify, c.Member.MemberId)
  158. if err != nil || bookResult.RoleId == conf.BookObserver {
  159. c.JsonResult(6002, "关联文档不存在或权限不足")
  160. }
  161. }
  162. }
  163. var blog *models.Blog
  164. var err error
  165. //如果文章ID存在,则从数据库中查询文章
  166. if blogId > 0 {
  167. if c.Member.IsAdministrator() {
  168. blog, err = models.NewBlog().Find(blogId)
  169. } else {
  170. blog, err = models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
  171. }
  172. if err != nil {
  173. c.JsonResult(6003, "文章不存在")
  174. }
  175. //如果设置了文章标识
  176. if blogIdentify != "" {
  177. //如果查询到的文章标识存在并且不是当前文章的id
  178. if b,err := models.NewBlog().FindByIdentify(blogIdentify); err == nil && b.BlogId != blogId {
  179. c.JsonResult(6004,"文章标识已存在")
  180. }
  181. }
  182. blog.Modified = time.Now()
  183. blog.ModifyAt = c.Member.MemberId
  184. }else{
  185. //如果设置了文章标识
  186. if blogIdentify != "" {
  187. if models.NewBlog().IsExist(blogIdentify) {
  188. c.JsonResult(6004,"文章标识已存在")
  189. }
  190. }
  191. blog = models.NewBlog()
  192. blog.MemberId = c.Member.MemberId
  193. blog.Created = time.Now()
  194. }
  195. if blogIdentify == "" {
  196. blog.BlogIdentify = fmt.Sprintf("%s-%d","post",time.Now().UnixNano())
  197. }else{
  198. blog.BlogIdentify = blogIdentify
  199. }
  200. blog.BlogTitle = blogTitle
  201. blog.OrderIndex = orderIndex
  202. blog.BlogType = blogType
  203. if blogType == 1 {
  204. blog.DocumentId = documentId
  205. }
  206. blog.BlogExcerpt = blogExcerpt
  207. blog.BlogStatus = blogStatus
  208. blog.Password = blogPassword
  209. if err := blog.Save();err != nil {
  210. beego.Error("保存文章失败 -> ",err)
  211. c.JsonResult(6011,"保存文章失败")
  212. }else{
  213. c.JsonResult(0,"ok",blog)
  214. }
  215. }
  216. if c.Ctx.Input.Referer() == "" {
  217. c.Data["Referer"] = "javascript:history.back();"
  218. }else{
  219. c.Data["Referer"] = c.Ctx.Input.Referer()
  220. }
  221. blogId,err := strconv.Atoi(c.Ctx.Input.Param(":id"))
  222. c.Data["DocumentIdentify"] = "";
  223. if err == nil {
  224. blog,err := models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  225. if err != nil {
  226. c.ShowErrorPage(500,err.Error())
  227. }
  228. c.Data["Model"] = blog
  229. }else{
  230. c.Data["Model"] = models.NewBlog()
  231. }
  232. }
  233. //文章创建或编辑
  234. func (c *BlogController) ManageEdit() {
  235. c.Prepare()
  236. c.TplName = "blog/manage_edit.tpl"
  237. if c.Ctx.Input.IsPost() {
  238. blogId,_ := c.GetInt("blogId",0)
  239. if blogId <= 0 {
  240. c.JsonResult(6001,"文章参数错误")
  241. }
  242. blogContent := c.GetString("content","")
  243. blogHtml := c.GetString("htmlContent","")
  244. version,_ := c.GetInt64("version",0)
  245. cover := c.GetString("cover")
  246. var blog *models.Blog
  247. var err error
  248. if c.Member.IsAdministrator() {
  249. blog,err = models.NewBlog().Find(blogId)
  250. }else{
  251. blog,err = models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  252. }
  253. if err != nil {
  254. beego.Error("查询文章失败 ->",err)
  255. c.JsonResult(6002,"查询文章失败")
  256. }
  257. if version > 0 && blog.Version != version && cover != "yes"{
  258. c.JsonResult(6005,"文章已被修改")
  259. }
  260. //如果是关联文章,需要同步关联的文档
  261. if blog.BlogType == 1 {
  262. doc,err := models.NewDocument().Find(blog.DocumentId)
  263. if err != nil {
  264. beego.Error("查询关联项目文档时出错 ->", err)
  265. c.JsonResult(6003,"查询关联项目文档时出错")
  266. }
  267. book, err := models.NewBook().Find(doc.BookId)
  268. if err != nil {
  269. c.JsonResult(6002, "项目不存在或权限不足")
  270. }
  271. // 如果不是超级管理员,则校验权限
  272. if !c.Member.IsAdministrator() {
  273. bookResult, err := models.NewBookResult().FindByIdentify(book.Identify, c.Member.MemberId)
  274. if err != nil || bookResult.RoleId == conf.BookObserver {
  275. beego.Error("FindByIdentify => ", err)
  276. c.JsonResult(6002, "关联文档不存在或权限不足")
  277. }
  278. }
  279. doc.Markdown = blogContent
  280. doc.Release = blogHtml
  281. doc.Content = blogHtml
  282. doc.ModifyTime = time.Now()
  283. doc.ModifyAt = c.Member.MemberId
  284. if err := doc.InsertOrUpdate("markdown","release","content","modify_time","modify_at");err != nil {
  285. beego.Error("保存关联文档时出错 ->",err)
  286. c.JsonResult(6004,"保存关联文档时出错")
  287. }
  288. }
  289. blog.BlogContent = blogContent
  290. blog.BlogRelease = blogHtml
  291. blog.ModifyAt = c.Member.MemberId
  292. blog.Modified = time.Now()
  293. if err := blog.Save("blog_content","blog_release","modify_at","modify_time","version");err != nil {
  294. beego.Error("保存文章失败 -> ",err)
  295. c.JsonResult(6011,"保存文章失败")
  296. }else{
  297. c.JsonResult(0,"ok",blog)
  298. }
  299. }
  300. blogId,_ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  301. if blogId <= 0 {
  302. c.ShowErrorPage(500,"参数错误")
  303. }
  304. var blog *models.Blog
  305. var err error
  306. if c.Member.IsAdministrator() {
  307. blog,err = models.NewBlog().Find(blogId)
  308. }else{
  309. blog,err = models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  310. }
  311. if err != nil {
  312. c.ShowErrorPage(404,"文章不存在或已删除")
  313. }
  314. blog.LinkAttach()
  315. if len(blog.AttachList) > 0 {
  316. returnJSON, err := json.Marshal(blog.AttachList)
  317. if err != nil {
  318. beego.Error("序列化文章附件时出错 ->",err)
  319. }else{
  320. c.Data["AttachList"] = template.JS(string(returnJSON))
  321. }
  322. }else{
  323. c.Data["AttachList"] = template.JS("[]")
  324. }
  325. if conf.GetUploadFileSize() > 0 {
  326. c.Data["UploadFileSize"] = conf.GetUploadFileSize()
  327. }else{
  328. c.Data["UploadFileSize"] = "undefined";
  329. }
  330. c.Data["Model"] = blog
  331. }
  332. //删除文章
  333. func (c *BlogController) ManageDelete() {
  334. c.Prepare()
  335. blogId,_ := c.GetInt("blog_id",0)
  336. if blogId <= 0 {
  337. c.JsonResult(6001,"参数错误")
  338. }
  339. var blog *models.Blog
  340. var err error
  341. if c.Member.IsAdministrator() {
  342. blog,err = models.NewBlog().Find(blogId)
  343. }else{
  344. blog,err = models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  345. }
  346. if err != nil {
  347. c.JsonResult(6002,"文章不存在或已删除")
  348. }
  349. if err := blog.Delete(blogId); err != nil {
  350. c.JsonResult(6003,"删除失败")
  351. }else{
  352. c.JsonResult(0,"删除成功")
  353. }
  354. }
  355. // 上传附件或图片
  356. func (c *BlogController) Upload() {
  357. blogId, _ := c.GetInt("blogId")
  358. if blogId <= 0 {
  359. c.JsonResult(6001, "参数错误")
  360. }
  361. blog,err := models.NewBlog().Find(blogId)
  362. if err != nil {
  363. c.JsonResult(6010,"文章不存在")
  364. }
  365. if !c.Member.IsAdministrator() && blog.MemberId != c.Member.MemberId {
  366. c.JsonResult(6011,"没有文章的访问权限")
  367. }
  368. name := "editormd-file-file"
  369. file, moreFile, err := c.GetFile(name)
  370. if err == http.ErrMissingFile {
  371. name = "editormd-image-file"
  372. file, moreFile, err = c.GetFile(name)
  373. if err == http.ErrMissingFile {
  374. c.JsonResult(6003, "没有发现需要上传的图片")
  375. }
  376. }
  377. if err != nil {
  378. c.JsonResult(6002, err.Error())
  379. }
  380. defer file.Close()
  381. type Size interface {
  382. Size() int64
  383. }
  384. if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() {
  385. c.JsonResult(6009, "查过文件允许的上传最大值")
  386. }
  387. ext := filepath.Ext(moreFile.Filename)
  388. if ext == "" {
  389. c.JsonResult(6003, "无法解析文件的格式")
  390. }
  391. //如果文件类型设置为 * 标识不限制文件类型
  392. if beego.AppConfig.DefaultString("upload_file_ext", "") != "*" {
  393. if !conf.IsAllowUploadFileExt(ext) {
  394. c.JsonResult(6004, "不允许的文件类型")
  395. }
  396. }
  397. // 如果是超级管理员,则不判断权限
  398. if c.Member.IsAdministrator() {
  399. _, err := models.NewBlog().Find(blogId)
  400. if err != nil {
  401. c.JsonResult(6006, "文档不存在或权限不足")
  402. }
  403. } else {
  404. _, err := models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
  405. if err != nil {
  406. beego.Error("查询文章时出错 -> ", err)
  407. if err == orm.ErrNoRows {
  408. c.JsonResult(6006, "权限不足")
  409. }
  410. c.JsonResult(6001, err.Error())
  411. }
  412. }
  413. fileName := "attach_" + strconv.FormatInt(time.Now().UnixNano(), 16)
  414. filePath := filepath.Join(conf.WorkingDirectory, "uploads", "blog", time.Now().Format("200601"), fileName+ext)
  415. path := filepath.Dir(filePath)
  416. os.MkdirAll(path, os.ModePerm)
  417. err = c.SaveToFile(name, filePath)
  418. if err != nil {
  419. beego.Error("SaveToFile => ", err)
  420. c.JsonResult(6005, "保存文件失败")
  421. }
  422. var httpPath string
  423. result := make(map[string]interface{})
  424. //如果是图片,则当做内置图片处理,否则当做附件处理
  425. if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, ".png") || strings.EqualFold(ext, ".gif") {
  426. httpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, conf.WorkingDirectory), "\\", "/", -1)
  427. if strings.HasPrefix(httpPath, "//") {
  428. httpPath = conf.URLForWithCdnImage(string(httpPath[1:]))
  429. }
  430. } else {
  431. attachment := models.NewAttachment()
  432. attachment.BookId = 0
  433. attachment.FileName = moreFile.Filename
  434. attachment.CreateAt = c.Member.MemberId
  435. attachment.FileExt = ext
  436. attachment.FilePath = strings.TrimPrefix(filePath, conf.WorkingDirectory)
  437. attachment.DocumentId = blogId
  438. //如果是关联文章,则将附件设置为关联文档的文档上
  439. if blog.BlogType == 1 {
  440. attachment.BookId = blog.BookId
  441. attachment.DocumentId = blog.DocumentId
  442. }
  443. if fileInfo, err := os.Stat(filePath); err == nil {
  444. attachment.FileSize = float64(fileInfo.Size())
  445. }
  446. attachment.HttpPath = httpPath
  447. if err := attachment.Insert(); err != nil {
  448. os.Remove(filePath)
  449. beego.Error("保存文件附件失败 => ", err)
  450. c.JsonResult(6006, "文件保存失败")
  451. }
  452. if attachment.HttpPath == "" {
  453. attachment.HttpPath = conf.URLFor("BlogController.Download", ":id", blogId, ":attach_id", attachment.AttachmentId)
  454. if err := attachment.Update(); err != nil {
  455. beego.Error("SaveToFile => ", err)
  456. c.JsonResult(6005, "保存文件失败")
  457. }
  458. }
  459. result["attach"] = attachment
  460. }
  461. result["errcode"] = 0
  462. result["success"] = 1
  463. result["message"] = "ok"
  464. result["url"] = httpPath
  465. result["alt"] = fileName
  466. c.Ctx.Output.JSON(result, true, false)
  467. c.StopRun()
  468. }
  469. // 删除附件
  470. func (c *BlogController) RemoveAttachment() {
  471. c.Prepare()
  472. attachId, _ := c.GetInt("attach_id")
  473. blogId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  474. if attachId <= 0 {
  475. c.JsonResult(6001, "参数错误")
  476. }
  477. blog, err := models.NewBlog().Find(blogId)
  478. if err != nil {
  479. if err == orm.ErrNoRows {
  480. c.ShowErrorPage(500, "文档不存在")
  481. } else {
  482. c.ShowErrorPage(500, "查询文章时异常")
  483. }
  484. }
  485. attach, err := models.NewAttachment().Find(attachId)
  486. if err != nil {
  487. beego.Error(err)
  488. c.JsonResult(6002, "附件不存在")
  489. }
  490. if !c.Member.IsAdministrator() {
  491. _, err := models.NewBlog().FindByIdAndMemberId(attach.DocumentId,c.Member.MemberId)
  492. if err != nil {
  493. beego.Error(err)
  494. c.JsonResult(6003, "文档不存在")
  495. }
  496. }
  497. if blog.BlogType == 1 && attach.BookId != blog.BookId && attach.DocumentId != blog.DocumentId {
  498. c.ShowErrorPage(404,"附件不存在")
  499. }else if attach.BookId !=0 || attach.DocumentId != blogId {
  500. c.ShowErrorPage(404,"附件不存在")
  501. }
  502. if err := attach.Delete();err != nil {
  503. beego.Error(err)
  504. c.JsonResult(6005, "删除失败")
  505. }
  506. os.Remove(filepath.Join(conf.WorkingDirectory, attach.FilePath))
  507. c.JsonResult(0, "ok", attach)
  508. }
  509. //下载附件
  510. func (c *BlogController) Download() {
  511. c.Prepare()
  512. blogId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  513. attachId, _ := strconv.Atoi(c.Ctx.Input.Param(":attach_id"))
  514. password := c.GetString("password")
  515. blog, err := models.NewBlog().Find(blogId)
  516. if err != nil {
  517. if err == orm.ErrNoRows {
  518. c.ShowErrorPage(500, "文档不存在")
  519. } else {
  520. c.ShowErrorPage(500, "查询文章时异常")
  521. }
  522. }
  523. blogReadSession := fmt.Sprintf("blog:read:%d",blogId)
  524. //如果没有启动匿名访问,或者设置了访问密码
  525. if (c.Member == nil && !c.EnableAnonymous) || ( blog.BlogStatus == "password" && password != blog.Password && c.CruSession.Get(blogReadSession) == nil) {
  526. c.ShowErrorPage(403, "没有下载权限")
  527. }
  528. // 查找附件
  529. attachment, err := models.NewAttachment().Find(attachId)
  530. if err != nil {
  531. beego.Error("DownloadAttachment => ", err)
  532. if err == orm.ErrNoRows {
  533. c.ShowErrorPage(404,"附件不存在")
  534. } else {
  535. c.ShowErrorPage(500,"查询附件时出现异常")
  536. }
  537. }
  538. if blog.BlogType == 1 && attachment.BookId != blog.BookId && attachment.DocumentId != blog.DocumentId {
  539. c.ShowErrorPage(404,"附件不存在")
  540. }else if attachment.BookId !=0 || attachment.DocumentId != blogId {
  541. c.ShowErrorPage(404,"附件不存在")
  542. }
  543. c.Ctx.Output.Download(filepath.Join(conf.WorkingDirectory, attachment.FilePath), attachment.FileName)
  544. c.StopRun()
  545. }