阅读文档.
()
| 229 | |
| 230 | // 阅读文档. |
| 231 | func (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 { |
no test coverage detected