diff --git a/controllers/base.go b/controllers/base.go index c830a790..f742f4de 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -123,7 +123,15 @@ func (c *BaseController) BaseUrl() string { //显示错误信息页面. func (c *BaseController) ShowErrorPage(errCode int, errMsg string) { c.TplName = "errors/error.tpl" + c.Data["ErrorMessage"] = errMsg c.Data["ErrorCode"] = errCode - c.StopRun() + + var buf bytes.Buffer + + if err := beego.ExecuteViewPathTemplate(&buf, "document/export.tpl", beego.BConfig.WebConfig.ViewsPath, map[string]interface{}{"ErrorMessage": errMsg, "errCode": errCode, "BaseUrl": conf.BaseUrl}); err != nil { + c.Abort("500") + } + + c.CustomAbort(200,buf.String()) } diff --git a/controllers/book.go b/controllers/book.go index c720cd02..493cb024 100644 --- a/controllers/book.go +++ b/controllers/book.go @@ -42,6 +42,10 @@ func (c *BookController) Index() { c.Abort("500") } + for i,book := range books { + books[i].Description = utils.StripTags(string(blackfriday.MarkdownBasic([]byte(book.Description)))) + } + if totalCount > 0 { pager := pagination.NewPagination(c.Ctx.Request,totalCount,conf.PageSize) c.Data["PageHtml"] = pager.HtmlPages() @@ -135,6 +139,7 @@ func (c *BookController) SaveBook() { autoRelease := strings.TrimSpace(c.GetString("auto_release")) == "on" publisher := strings.TrimSpace(c.GetString("publisher")) historyCount,_ := c.GetInt("history_count",0) + isDownload := strings.TrimSpace(c.GetString("is_download")) == "on" if strings.Count(description, "") > 500 { c.JsonResult(6004, "项目描述不能大于500字") @@ -159,13 +164,18 @@ func (c *BookController) SaveBook() { book.Label = tag book.Editor = editor book.HistoryCount = historyCount + book.IsDownload = 0 if autoRelease { book.AutoRelease = 1 } else { book.AutoRelease = 0 } - + if isDownload { + book.IsDownload = 0 + }else{ + book.IsDownload = 1 + } if err := book.Update(); err != nil { c.JsonResult(6006, "保存失败") } @@ -395,7 +405,7 @@ func (c *BookController) Create() { book_name := strings.TrimSpace(c.GetString("book_name", "")) identify := strings.TrimSpace(c.GetString("identify", "")) description := strings.TrimSpace(c.GetString("description", "")) - privately_owned, _ := strconv.Atoi(c.GetString("privately_owned")) + privatelyOwned, _ := strconv.Atoi(c.GetString("privately_owned")) comment_status := c.GetString("comment_status") if book_name == "" { @@ -413,8 +423,8 @@ func (c *BookController) Create() { if strings.Count(description, "") > 500 { c.JsonResult(6004, "项目描述不能大于500字") } - if privately_owned != 0 && privately_owned != 1 { - privately_owned = 1 + if privatelyOwned != 0 && privatelyOwned != 1 { + privatelyOwned = 1 } if comment_status != "open" && comment_status != "closed" && comment_status != "group_only" && comment_status != "registered_only" { comment_status = "closed" @@ -460,7 +470,7 @@ func (c *BookController) Create() { book.BookName = book_name book.Description = description book.CommentCount = 0 - book.PrivatelyOwned = privately_owned + book.PrivatelyOwned = privatelyOwned book.CommentStatus = comment_status book.Identify = identify book.DocCount = 0 @@ -487,7 +497,7 @@ func (c *BookController) Create() { } c.JsonResult(6001, "error") } - +//导入 func (c *BookController) Import() { file, moreFile, err := c.GetFile("import-file") diff --git a/controllers/document.go b/controllers/document.go index a8cfdd96..1f4e0bae 100644 --- a/controllers/document.go +++ b/controllers/document.go @@ -169,13 +169,13 @@ func (c *DocumentController) Read() { doc := models.NewDocument() if doc_id, err := strconv.Atoi(id); err == nil { - doc, err = doc.Find(doc_id) + doc, err = doc.FromCacheById(doc_id) if err != nil { beego.Error(err) c.Abort("500") } } else { - doc, err = doc.FindByFieldFirst("identify", id) + doc, err = doc.FromCacheByIdentify(id) if err != nil { beego.Error(err) c.Abort("500") @@ -723,14 +723,14 @@ func (c *DocumentController) Content() { c.Prepare() identify := c.Ctx.Input.Param(":key") - doc_id, err := c.GetInt("doc_id") + docId, err := c.GetInt("doc_id") if err != nil { - doc_id, _ = strconv.Atoi(c.Ctx.Input.Param(":id")) + docId, _ = strconv.Atoi(c.Ctx.Input.Param(":id")) } - book_id := 0 - auto_release := false + bookId := 0 + autoRelease := false // 如果是超级管理员,则忽略权限 if c.Member.IsAdministrator() { @@ -739,8 +739,8 @@ func (c *DocumentController) Content() { c.JsonResult(6002, "项目不存在或权限不足") } - book_id = book.BookId - auto_release = book.AutoRelease == 1 + bookId = book.BookId + autoRelease = book.AutoRelease == 1 } else { bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId) @@ -749,11 +749,11 @@ func (c *DocumentController) Content() { c.JsonResult(6002, "项目不存在或权限不足") } - book_id = bookResult.BookId - auto_release = bookResult.AutoRelease + bookId = bookResult.BookId + autoRelease = bookResult.AutoRelease } - if doc_id <= 0 { + if docId <= 0 { c.JsonResult(6001, "参数错误") } @@ -761,25 +761,25 @@ func (c *DocumentController) Content() { markdown := strings.TrimSpace(c.GetString("markdown", "")) content := c.GetString("html") version, _ := c.GetInt64("version", 0) - is_cover := c.GetString("cover") + isCover := c.GetString("cover") - doc, err := models.NewDocument().Find(doc_id) + doc, err := models.NewDocument().Find(docId) if err != nil { c.JsonResult(6003, "读取文档错误") } - if doc.BookId != book_id { + if doc.BookId != bookId { c.JsonResult(6004, "保存的文档不属于指定项目") } - if doc.Version != version && !strings.EqualFold(is_cover, "yes") { + if doc.Version != version && !strings.EqualFold(isCover, "yes") { beego.Info("%d|", version, doc.Version) c.JsonResult(6005, "文档已被修改确定要覆盖吗?") } history := models.NewDocumentHistory() - history.DocumentId = doc_id + history.DocumentId = docId history.Content = doc.Content history.Markdown = doc.Markdown history.DocumentName = doc.DocumentName @@ -812,9 +812,9 @@ func (c *DocumentController) Content() { } } //如果启用了自动发布 - if auto_release { + if autoRelease { go func(identify string) { - models.NewDocument().ReleaseContent(book_id) + models.NewDocument().ReleaseContent(bookId) }(identify) } @@ -822,7 +822,7 @@ func (c *DocumentController) Content() { c.JsonResult(0, "ok", doc) } - doc, err := models.NewDocument().Find(doc_id) + doc, err := models.NewDocument().Find(docId) if err != nil { c.JsonResult(6003, "文档不存在") } @@ -883,6 +883,9 @@ func (c *DocumentController) Export() { } else { bookResult = isReadable(identify, token, c) } + if !bookResult.IsDownload { + c.ShowErrorPage(200,"当前项目没有开启导出功能") + } if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") { bookResult.Cover = c.BaseUrl() + bookResult.Cover @@ -911,6 +914,8 @@ func (c *DocumentController) Export() { c.Ctx.Output.Download(eBookResult.WordPath, bookResult.BookName+".docx") c.Abort("200") + }else{ + c.ShowErrorPage(200,"不支持的文件格式") } c.Abort("404") diff --git a/controllers/label.go b/controllers/label.go index 17cbba1d..0f357fa3 100644 --- a/controllers/label.go +++ b/controllers/label.go @@ -47,7 +47,7 @@ func (c *LabelController) Index() { if c.Member != nil { member_id = c.Member.MemberId } - search_result, totalCount, err := models.NewBook().FindForLabelToPager(labelName, pageIndex, conf.PageSize, member_id) + searchResult, totalCount, err := models.NewBook().FindForLabelToPager(labelName, pageIndex, conf.PageSize, member_id) if err != nil { beego.Error(err) @@ -59,7 +59,7 @@ func (c *LabelController) Index() { } else { c.Data["PageHtml"] = "" } - c.Data["Lists"] = search_result + c.Data["Lists"] = searchResult c.Data["LabelName"] = labelName } diff --git a/controllers/manager.go b/controllers/manager.go index 1739c2fe..0f7d8a5d 100644 --- a/controllers/manager.go +++ b/controllers/manager.go @@ -15,6 +15,7 @@ import ( "path/filepath" "strconv" "github.com/lifei6671/mindoc/utils/pagination" + "math" ) type ManagerController struct { @@ -633,3 +634,66 @@ func (c *ManagerController) AttachDelete() { } c.JsonResult(0, "ok") } + +//标签列表 +func (c *ManagerController) LabelList(){ + c.Prepare() + c.TplName = "manager/label_list.tpl" + + pageIndex, _ := c.GetInt("page", 1) + + labels, totalCount, err := models.NewLabel().FindToPager(pageIndex, conf.PageSize) + + if err != nil { + c.ShowErrorPage(50001, err.Error()) + } + if totalCount > 0 { + pager := pagination.NewPagination(c.Ctx.Request,totalCount,conf.PageSize) + c.Data["PageHtml"] = pager.HtmlPages() + } else { + c.Data["PageHtml"] = "" + } + c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(conf.PageSize))) + + c.Data["Lists"] = labels +} +//删除标签 +func (c *ManagerController) LabelDelete(){ + labelId,err := strconv.Atoi(c.Ctx.Input.Param(":id")) + + if err != nil { + beego.Error("获取删除标签参数时出错:",err) + c.JsonResult(50001,"参数错误") + } + if labelId <= 0 { + c.JsonResult(50001,"参数错误") + } + + label,err := models.NewLabel().FindFirst("label_id",labelId) + if err != nil { + beego.Error("查询标签时出错:",err) + c.JsonResult(50001,"查询标签时出错:" + err.Error()) + } + if err := label.Delete();err != nil { + c.JsonResult(50002,"删除失败:" + err.Error()) + }else{ + c.JsonResult(0,"ok") + } +} + + + + + + + + + + + + + + + + + diff --git a/controllers/search.go b/controllers/search.go index bcdc9e22..2644659f 100644 --- a/controllers/search.go +++ b/controllers/search.go @@ -4,8 +4,8 @@ import ( "github.com/astaxie/beego" "github.com/lifei6671/mindoc/conf" "github.com/lifei6671/mindoc/models" + "github.com/lifei6671/mindoc/utils" "github.com/lifei6671/mindoc/utils/pagination" - "regexp" "strconv" "strings" ) @@ -13,6 +13,7 @@ import ( type SearchController struct { BaseController } + //搜索首页 func (c *SearchController) Index() { c.Prepare() @@ -42,7 +43,7 @@ func (c *SearchController) Index() { return } if totalCount > 0 { - pager := pagination.NewPagination(c.Ctx.Request,totalCount,conf.PageSize) + pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize) c.Data["PageHtml"] = pager.HtmlPages() } else { c.Data["PageHtml"] = "" @@ -54,27 +55,7 @@ func (c *SearchController) Index() { if item.Description != "" { src := item.Description - //将HTML标签全转换成小写 - re, _ := regexp.Compile("\\<[\\S\\s]+?\\>") - src = re.ReplaceAllStringFunc(src, strings.ToLower) - - //去除STYLE - re, _ = regexp.Compile("\\") + src = re.ReplaceAllString(src, "") + + //去除SCRIPT + re, _ = regexp.Compile("\\ + + + +
+# | +标签名称 | +使用数量 | +操作 | +||
---|---|---|---|---|---|
{{$item.LabelId}} | +{{$item.LabelName}} | +{{$item.BookNumber}} | ++ + 详情 + + | +||
暂无数据 |