Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gsw945/mindoc into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gsw945 committed May 7, 2022
2 parents 0671b0c + cf628f0 commit 8ff4c28
Show file tree
Hide file tree
Showing 12 changed files with 690 additions and 37 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ MinDoc 的前身是 [SmartWiki](https://github.com/lifei6671/SmartWiki) 文档

可以用来储存日常接口文档,数据库字典,手册说明等文档。内置项目管理,用户管理,权限管理等功能,能够满足大部分中小团队的文档管理需求。

##### 演示站点:
- [https://www.iminho.me/wiki/](https://www.iminho.me/wiki/)
- https://doc.gsw945.com/
##### 演示站点&文档:
- https://www.iminho.me/wiki/docs/mindoc/
- https://doc.gsw945.com/docs/mindoc-docs/

---

Expand Down
2 changes: 1 addition & 1 deletion conf/lang/zh-cn.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ project_id_existed = 文档标识已被使用
project_id_error = 项目标识有误
project_id_length = 项目标识必须小于50字符
import_file_empty = 请选择需要上传的文件
file_type_placeholder = 请选择Zip文件
file_type_placeholder = 请选择Zip或Docx文件
publish_to_queue = 发布任务已推送到任务队列,稍后将在后台执行。
team_name_empty = 团队名称不能为空
operate_failed = 操作失败
Expand Down
12 changes: 8 additions & 4 deletions controllers/BookController.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (c *BookController) UploadCover() {
fileName := "cover_" + strconv.FormatInt(time.Now().UnixNano(), 16)

//附件路径按照项目组织
// filePath := filepath.Join("uploads", book.Identify, "images", fileName+ext)
// filePath := filepath.Join("uploads", book.Identify, "images", fileName+ext)
filePath := filepath.Join(conf.WorkingDirectory, "uploads", book.Identify, "images", fileName+ext)

path := filepath.Dir(filePath)
Expand Down Expand Up @@ -571,7 +571,7 @@ func (c *BookController) Copy() {
}
}

//导入zip压缩包
// 导入zip压缩包或docx
func (c *BookController) Import() {

file, moreFile, err := c.GetFile("import-file")
Expand Down Expand Up @@ -608,7 +608,7 @@ func (c *BookController) Import() {

ext := filepath.Ext(moreFile.Filename)

if !strings.EqualFold(ext, ".zip") {
if !strings.EqualFold(ext, ".zip") && !strings.EqualFold(ext, ".docx") {
c.JsonResult(6004, "不支持的文件类型")
}

Expand Down Expand Up @@ -643,7 +643,11 @@ func (c *BookController) Import() {
book.Editor = "markdown"
book.Theme = "default"

go book.ImportBook(tempPath, c.Lang)
if strings.EqualFold(ext, ".zip") {
go book.ImportBook(tempPath, c.Lang)
} else if strings.EqualFold(ext, ".docx") {
go book.ImportWordBook(tempPath, c.Lang)
}

logs.Info("用户[", c.Member.Account, "]导入了项目 ->", book)

Expand Down
47 changes: 25 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
MinDoc_New:
image: registry.cn-hangzhou.aliyuncs.com/mindoc/mindoc:v2.0-beta.5
privileged: false
restart: always
ports:
- 8181:8181
volumes:
- /var/www/mindoc://mindoc-sync-host
environment:
- MINDOC_RUN_MODE=prod
- MINDOC_DB_ADAPTER=sqlite3
- MINDOC_DB_DATABASE=./database/mindoc.db
- MINDOC_CACHE=true
- MINDOC_CACHE_PROVIDER=file
- MINDOC_ENABLE_EXPORT=false
- MINDOC_BASE_URL=
- MINDOC_CDN_IMG_URL=
- MINDOC_CDN_CSS_URL=
- MINDOC_CDN_JS_URL=
dns:
- 223.5.5.5
- 223.6.6.6
version: "3"
services:
mindoc:
image: registry.cn-hangzhou.aliyuncs.com/mindoc-org/mindoc:v2.1-beta.5
container_name: mindoc
privileged: false
restart: always
ports:
- 8181:8181
volumes:
- /var/www/mindoc://mindoc-sync-host
environment:
- MINDOC_RUN_MODE=prod
- MINDOC_DB_ADAPTER=sqlite3
- MINDOC_DB_DATABASE=./database/mindoc.db
- MINDOC_CACHE=true
- MINDOC_CACHE_PROVIDER=file
- MINDOC_ENABLE_EXPORT=false
- MINDOC_BASE_URL=
- MINDOC_CDN_IMG_URL=
- MINDOC_CDN_CSS_URL=
- MINDOC_CDN_JS_URL=
dns:
- 223.5.5.5
- 223.6.6.6
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
74 changes: 73 additions & 1 deletion models/BookModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func (book *Book) ResetDocumentNumber(bookId int) {
}
}

//导入项目
// 导入zip项目
func (book *Book) ImportBook(zipPath string, lang string) error {
if !filetil.FileExists(zipPath) {
return errors.New("文件不存在 => " + zipPath)
Expand Down Expand Up @@ -978,6 +978,78 @@ func (book *Book) ImportBook(zipPath string, lang string) error {
return err
}

// 导入docx项目
func (book *Book) ImportWordBook(docxPath string, lang string) (err error) {
if !filetil.FileExists(docxPath) {
return errors.New("文件不存在")
}
docxPath = strings.Replace(docxPath, "\\", "/", -1)

o := orm.NewOrm()

o.Insert(book)
relationship := NewRelationship()
relationship.BookId = book.BookId
relationship.RoleId = 0
relationship.MemberId = book.MemberId
err = relationship.Insert()
if err != nil {
logs.Error("插入项目与用户关联 -> ", err)
return err
}

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
}

doc.Identify = docIdentify

if doc.Markdown, err = utils.Docx2md(docxPath, false); err != nil {
logs.Error("导入doc项目转换异常 => ", err)
return err
}

// fmt.Println("===doc.Markdown===")
// fmt.Println(doc.Markdown)
// fmt.Println("==================")

doc.Content = string(blackfriday.Run([]byte(doc.Markdown)))

// fmt.Println("===doc.Content===")
// fmt.Println(doc.Content)
// fmt.Println("==================")

doc.Version = time.Now().Unix()

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.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
}

func (book *Book) FindForRoleId(bookId, memberId int) (conf.BookRole, error) {
o := orm.NewOrm()

Expand Down
4 changes: 2 additions & 2 deletions static/css/kancloud.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ table>tbody>tr:hover{
right: 0;
overflow-y: auto;
background-color: #fafafa;
margin-bottom: 35px;
margin-bottom: 60px;
}

.m-manual .manual-tab .tab-item.active {
Expand Down Expand Up @@ -1173,4 +1173,4 @@ table>tbody>tr:hover{
opacity: .3;
z-index: 3000
}
}
}
Loading

0 comments on commit 8ff4c28

Please sign in to comment.