MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Get

Method Get

controllers/HomeControllers/ViewController.go:20–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func (this *ViewController) Get() {
21 id, _ := this.GetInt(":id")
22 if id < 1 {
23 this.Redirect("/", 302)
24 return
25 }
26
27 doc, err := models.NewDocument().GetById(id)
28
29 // 文档不存在、查询错误、被删除,报 404
30 if err != nil || doc.Id <= 0 || doc.Status < models.DocStatusConverting {
31 this.Abort("404")
32 }
33
34 var cates []models.Category
35 cates, _ = models.NewCategory().GetCategoriesById(doc.Cid, doc.ChanelId, doc.Pid)
36 breadcrumb := make(map[string]models.Category)
37 for _, cate := range cates {
38 switch cate.Id {
39 case doc.ChanelId:
40 breadcrumb["Chanel"] = cate
41 case doc.Pid:
42 breadcrumb["Parent"] = cate
43 case doc.Cid:
44 TimeStart := int(time.Now().Unix()) - this.Sys.TimeExpireHotspot
45 this.Data["Hots"], _, _ = models.NewDocument().SimpleList(fmt.Sprintf("di.Cid=%v and di.TimeCreate>%v", doc.Cid, TimeStart), 10, "Dcnt")
46 this.Data["Latest"], _, _ = models.NewDocument().SimpleList(fmt.Sprintf("di.Cid=%v", doc.Cid), 10, "Id")
47 breadcrumb["Child"] = cate
48 }
49 }
50 this.Data["Breadcrumb"] = breadcrumb
51
52 models.Regulate(models.GetTableDocumentInfo(), "Vcnt", 1, "`Id`=?", id)
53
54 pageShow := 5
55 if doc.Page > pageShow {
56 this.Data["PreviewPages"] = make([]string, pageShow)
57 } else {
58 this.Data["PreviewPages"] = make([]string, doc.Page)
59 }
60 this.Data["PageShow"] = pageShow
61
62 this.Xsrf()
63 if this.Data["Comments"], _, err = models.NewDocumentComment().GetCommentList(id, 1, 10); err != nil {
64 helper.Logger.Error(err.Error())
65 }
66
67 content := models.NewDocText().GetDescByMd5(doc.Md5, 5000)
68 seoTitle := fmt.Sprintf("%v - %v · %v · %v ", doc.Title, breadcrumb["Chanel"].Title, breadcrumb["Parent"].Title, breadcrumb["Child"].Title)
69 seoKeywords := fmt.Sprintf("%v,%v,%v,", breadcrumb["Chanel"].Title, breadcrumb["Parent"].Title, breadcrumb["Child"].Title) + doc.Keywords
70 seoDesc := beego.Substr(doc.Description+content, 0, 255)
71 this.Data["Seo"] = models.NewSeo().GetByPage("PC-View", seoTitle, seoKeywords, seoDesc, this.Sys.Site)
72 this.Data["Content"] = content
73 this.Data["Reasons"] = models.NewSys().GetReportReasons()
74 this.Data["IsViewer"] = true
75 this.Data["PageId"] = "wenku-content"
76 this.Data["Doc"] = doc
77

Callers

nothing calls this directly

Calls 8

GetCategoriesByIdMethod · 0.80
SimpleListMethod · 0.80
GetCommentListMethod · 0.80
GetDescByMd5Method · 0.80
GetByPageMethod · 0.80
GetReportReasonsMethod · 0.80
GetByIdMethod · 0.45
XsrfMethod · 0.45

Tested by

no test coverage detected