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

Method CreateMulti

controllers/DocumentController.go:696–738  ·  view source on GitHub ↗

批量创建文档

()

Source from the content-addressed store, hash-verified

694
695// 批量创建文档
696func (this *DocumentController) CreateMulti() {
697 bookId, _ := this.GetInt("book_id")
698
699 if !(this.Member.MemberId > 0 && bookId > 0) {
700 this.JsonResult(1, "操作失败:只有书籍创始人才能批量添加")
701 }
702
703 var book models.Book
704 o := orm.NewOrm()
705 o.QueryTable("md_books").Filter("book_id", bookId).Filter("member_id", this.Member.MemberId).One(&book, "book_id")
706 if book.BookId > 0 {
707 content := this.GetString("content")
708 slice := strings.Split(content, "\n")
709 if len(slice) > 0 {
710 ModelStore := new(models.DocumentStore)
711 for _, row := range slice {
712 if chapter := strings.Split(strings.TrimSpace(row), " "); len(chapter) > 1 {
713 if ok, err := regexp.MatchString(`^[a-zA-Z0-9_\-\.]*$`, chapter[0]); ok && err == nil {
714 i, _ := strconv.Atoi(chapter[0])
715 if chapter[0] != "0" && strconv.Itoa(i) != chapter[0] { //不为纯数字
716 doc := models.Document{
717 DocumentName: strings.Join(chapter[1:], " "),
718 Identify: chapter[0],
719 BookId: bookId,
720 //Markdown: "[TOC]\n\r",
721 MemberId: this.Member.MemberId,
722 }
723 if docId, err := doc.InsertOrUpdate(); err == nil {
724 if err := ModelStore.InsertOrUpdate(models.DocumentStore{DocumentId: int(docId), Markdown: "[TOC]\n\r\n\r"}); err != nil {
725 beego.Error(err.Error())
726 }
727 } else {
728 beego.Error(err)
729 }
730 }
731
732 }
733 }
734 }
735 }
736 }
737 this.JsonResult(0, "添加成功")
738}
739
740// 上传附件或图片.
741func (this *DocumentController) Upload() {

Callers

nothing calls this directly

Calls 3

InsertOrUpdateMethod · 0.95
JsonResultMethod · 0.80
InsertOrUpdateMethod · 0.45

Tested by

no test coverage detected