Augists 3 ani în urmă
părinte
comite
4eec37e7c9
3 a modificat fișierele cu 31 adăugiri și 24 ștergeri
  1. 1 0
      go.mod
  2. 4 0
      go.sum
  3. 26 24
      models/BookModel.go

+ 1 - 0
go.mod

@@ -14,6 +14,7 @@ require (
 	github.com/kardianos/service v1.1.0
 	github.com/lib/pq v1.7.0 // indirect
 	github.com/lifei6671/gocaptcha v0.1.1
+	github.com/mattn/go-runewidth v0.0.13
 	github.com/mattn/go-sqlite3 v2.0.3+incompatible
 	github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
 	github.com/russross/blackfriday/v2 v2.1.0

+ 4 - 0
go.sum

@@ -126,6 +126,8 @@ github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY=
 github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/lifei6671/gocaptcha v0.1.1 h1:5cvU3w0bK8eJm1P6AiQoPuicoZVAgKKpREBxXF9IaHo=
 github.com/lifei6671/gocaptcha v0.1.1/go.mod h1:6QlTU2WzFhzqylAJWSo3OANfKCraGccJwbK01P5fFmI=
+github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
+github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
@@ -174,6 +176,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
 github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
 github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
 github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
+github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
+github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
 github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

+ 26 - 24
models/BookModel.go

@@ -979,49 +979,51 @@ func (book *Book) ImportBook(zipPath string, lang string) error {
 }
 
 // 导入docx项目
-func (book *Book) ImportWordBook(docxPath string, lang string) error {
+func (book *Book) ImportWordBook(docxPath string, lang string) (err error) {
 	if !filetil.FileExists(docxPath) {
 		return errors.New("文件不存在")
 	}
-  docxPath = strings.Replace(docxPath, "\\", "/", -1)
+	docxPath = strings.Replace(docxPath, "\\", "/", -1)
 
 	o := orm.NewOrm()
 
 	o.Insert(book)
 	relationship := NewRelationship()
 	relationship.BookId = book.BookId
-	relationship.RoldId = 0
+	// relationship.RoldId = 0
 	relationship.MemberId = book.MemberId
 	relationship.Insert()
 
-  doc := NewDocument()
-  doc.BookId = book.BookId
-  doc.MemberId = book.MemberId
-  docIdentify := strings.Replace(strings.TrimPrefix(docxPath, os.TempDir()+"/"), "/", "-", -1)
+	doc := NewDocument()
+	doc.BookId = book.BookId
+	doc.MemberId = book.MemberId
+	docIdentify := strings.Replace(strings.TrimPrefix(docxPath, os.TempDir()+"/"), "/", "-", -1)
 
-  if ok, err := regexp.MatchString(`[a-z]+[a-zA-Z0-9_.\-]*$`, docIdentify); !ok || err != nil {
-    docIdentify = "import-" + docIdentify
-  }
+	if ok, err := regexp.MatchString(`[a-z]+[a-zA-Z0-9_.\-]*$`, docIdentify); !ok || err != nil {
+		docIdentify = "import-" + docIdentify
+	}
 
-  doc.Identify = docIdentify
+	doc.Identify = docIdentify
 
-	if doc.Markdown, err := util.Docx2md(docxPath, false); err != nil {
-    logs.Error("导入doc项目转换异常 => ", err)
-    exit(1)
-  }
+	if doc.Markdown, err = utils.Docx2md(docxPath, false); err != nil {
+		logs.Error("导入doc项目转换异常 => ", err)
+		return err
+	}
 
-  doc.Content = string(blackfriday.Run([]byte(doc.Markdown)))
+	doc.Content = string(blackfriday.Run([]byte(doc.Markdown)))
 
-  doc.Version = time.Now().Unix()
+	doc.Version = time.Now().Unix()
 
-  for _, line := range strings.Split(doc.Markdown, "\n") {
-    if strings.HasPrefix(line, "#") {
-      docName := strings.TrimLeft(line, "#")
-      break
-    }
-  }
+	var docName string
+	for _, line := range strings.Split(doc.Markdown, "\n") {
+		if strings.HasPrefix(line, "#") {
+			docName = strings.TrimLeft(line, "#")
+			break
+		}
+	}
 
-  doc.DocumentName = strings.TrimSpace(docName)
+	doc.DocumentName = strings.TrimSpace(docName)
+	return err
 }
 
 func (book *Book) FindForRoleId(bookId, memberId int) (conf.BookRole, error) {