mirror of https://github.com/mindoc-org/mindoc.git
add support for importing docx file as book
parent
f3c1c4bd3a
commit
63c0ac0a1d
|
@ -127,7 +127,7 @@ project_id_existed = 文档标识已被使用
|
||||||
project_id_error = 项目标识有误
|
project_id_error = 项目标识有误
|
||||||
project_id_length = 项目标识必须小于50字符
|
project_id_length = 项目标识必须小于50字符
|
||||||
import_file_empty = 请选择需要上传的文件
|
import_file_empty = 请选择需要上传的文件
|
||||||
file_type_placeholder = 请选择Zip文件
|
file_type_placeholder = 请选择Zip或Docx文件
|
||||||
publish_to_queue = 发布任务已推送到任务队列,稍后将在后台执行。
|
publish_to_queue = 发布任务已推送到任务队列,稍后将在后台执行。
|
||||||
team_name_empty = 团队名称不能为空
|
team_name_empty = 团队名称不能为空
|
||||||
operate_failed = 操作失败
|
operate_failed = 操作失败
|
||||||
|
|
|
@ -990,9 +990,13 @@ func (book *Book) ImportWordBook(docxPath string, lang string) (err error) {
|
||||||
o.Insert(book)
|
o.Insert(book)
|
||||||
relationship := NewRelationship()
|
relationship := NewRelationship()
|
||||||
relationship.BookId = book.BookId
|
relationship.BookId = book.BookId
|
||||||
// relationship.RoldId = 0
|
relationship.RoleId = 0
|
||||||
relationship.MemberId = book.MemberId
|
relationship.MemberId = book.MemberId
|
||||||
relationship.Insert()
|
err = relationship.Insert()
|
||||||
|
if err != nil {
|
||||||
|
logs.Error("插入项目与用户关联 -> ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
doc := NewDocument()
|
doc := NewDocument()
|
||||||
doc.BookId = book.BookId
|
doc.BookId = book.BookId
|
||||||
|
@ -1010,8 +1014,16 @@ func (book *Book) ImportWordBook(docxPath string, lang string) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fmt.Println("===doc.Markdown===")
|
||||||
|
// fmt.Println(doc.Markdown)
|
||||||
|
// fmt.Println("==================")
|
||||||
|
|
||||||
doc.Content = string(blackfriday.Run([]byte(doc.Markdown)))
|
doc.Content = string(blackfriday.Run([]byte(doc.Markdown)))
|
||||||
|
|
||||||
|
// fmt.Println("===doc.Content===")
|
||||||
|
// fmt.Println(doc.Content)
|
||||||
|
// fmt.Println("==================")
|
||||||
|
|
||||||
doc.Version = time.Now().Unix()
|
doc.Version = time.Now().Unix()
|
||||||
|
|
||||||
var docName string
|
var docName string
|
||||||
|
@ -1023,6 +1035,18 @@ func (book *Book) ImportWordBook(docxPath string, lang string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.DocumentName = strings.TrimSpace(docName)
|
doc.DocumentName = strings.TrimSpace(docName)
|
||||||
|
|
||||||
|
doc.DocumentId = book.MemberId
|
||||||
|
|
||||||
|
if err := doc.InsertOrUpdate("document_name", "book_id", "markdown", "content"); err != nil {
|
||||||
|
logs.Error(doc.DocumentId, err)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
logs.Error("导入项目异常 => ", err)
|
||||||
|
book.Description = "【项目导入存在错误:" + err.Error() + "】"
|
||||||
|
}
|
||||||
|
logs.Info("项目导入完毕 => ", book.BookName)
|
||||||
|
book.ReleaseContent(book.BookId, lang)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue