MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Read

Method Read

controllers/DocumentController.go:231–496  ·  view source on GitHub ↗

阅读文档.

()

Source from the content-addressed store, hash-verified

229
230// 阅读文档.
231func (this *DocumentController) Read() {
232
233 identify := this.Ctx.Input.Param(":key")
234 token := this.GetString("token")
235 id := this.GetString(":id")
236
237 if identify == "" || id == "" {
238 this.Abort("404")
239 }
240
241 //如果没有开启你们匿名则跳转到登录
242 if !this.EnableAnonymous && this.Member == nil {
243 this.Redirect(beego.URLFor("AccountController.Login"), 302)
244 return
245 }
246
247 bookResult := isReadable(identify, token, this)
248 bookName := bookResult.BookName
249 bookLink := beego.URLFor("DocumentController.Index", ":key", bookResult.Identify)
250
251 this.TplName = "document/" + bookResult.Theme + "_read.html"
252
253 var err error
254
255 doc := models.NewDocument()
256 if docId, _ := strconv.Atoi(id); docId > 0 {
257 doc, err = doc.Find(docId) //文档id
258 if err != nil {
259 beego.Error(err)
260 this.Abort404(bookName, bookLink)
261 }
262 } else {
263 //此处的id是字符串,标识文档标识,根据文档标识和文档所属的书的id作为key去查询
264 doc, err = doc.FindByBookIdAndDocIdentify(bookResult.BookId, id) //文档标识
265 if err != nil {
266 if err != orm.ErrNoRows {
267 beego.Error(err, docId, id, bookResult)
268 }
269 this.Abort404(bookName, bookLink)
270 }
271 }
272
273 if doc.BookId != bookResult.BookId {
274 this.Abort404(bookName, bookLink)
275 }
276
277 // 是否允许阅读
278 isAllowRead := true
279 percent := 100
280 if this.Member.MemberId == 0 {
281 isAllowRead, percent = doc.IsAllowReadChapter(doc.BookId, doc.DocumentId)
282 }
283
284 bodyText := ""
285 authHTTPS := strings.ToLower(models.GetOptionValue("AUTO_HTTPS", "false")) == "true"
286 if doc.Release != "" {
287 query, err := goquery.NewDocumentFromReader(bytes.NewBufferString(doc.Release))
288 if err != nil {

Callers 13

saltSecretFunction · 0.45
StarMethod · 0.45
DoesStarMethod · 0.45
UpdateRoleIdMethod · 0.45
GenerateBookMethod · 0.45
RestoreMethod · 0.45
generateMethod · 0.45
FindMethod · 0.45
DelMethod · 0.45
FindMethod · 0.45
AddScoreMethod · 0.45
UpdateMethod · 0.45

Calls 15

FindMethod · 0.95
Abort404Method · 0.95
IsAllowReadChapterMethod · 0.95
GetParentTitleMethod · 0.95
CreateWechatCodeMethod · 0.95
GetCodeMethod · 0.95
NewDocumentFunction · 0.92
GetOptionValueFunction · 0.92
GenerateMediaSignFunction · 0.92
NewAttachmentFunction · 0.92
SetIncreAndDecreFunction · 0.92

Tested by

no test coverage detected