mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||
@@ -115,7 +116,7 @@ func NewBook() *Book {
|
||||
}
|
||||
|
||||
//添加一个项目
|
||||
func (book *Book) Insert() error {
|
||||
func (book *Book) Insert(lang string) error {
|
||||
o := orm.NewOrm()
|
||||
// o.Begin()
|
||||
book.BookName = utils.StripTags(book.BookName)
|
||||
@@ -141,7 +142,7 @@ func (book *Book) Insert() error {
|
||||
}
|
||||
document := NewDocument()
|
||||
document.BookId = book.BookId
|
||||
document.DocumentName = "空白文档"
|
||||
document.DocumentName = i18n.Tr(lang, "init.blank_doc") //"空白文档"
|
||||
document.MemberId = book.MemberId
|
||||
err = document.InsertOrUpdate()
|
||||
if err != nil {
|
||||
@@ -362,7 +363,7 @@ func (book *Book) FindByIdentify(identify string, cols ...string) (*Book, error)
|
||||
}
|
||||
|
||||
//分页查询指定用户的项目
|
||||
func (book *Book) FindToPager(pageIndex, pageSize, memberId int) (books []*BookResult, totalCount int, err error) {
|
||||
func (book *Book) FindToPager(pageIndex, pageSize, memberId int, lang string) (books []*BookResult, totalCount int, err error) {
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
@@ -430,13 +431,13 @@ ORDER BY book.order_index, book.book_id DESC limit ?,?`
|
||||
books[index].LastModifyText = text.Account + " 于 " + text.ModifyTime.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if book.RoleId == 0 {
|
||||
book.RoleName = "创始人"
|
||||
book.RoleName = i18n.Tr(lang, "common.creator")
|
||||
} else if book.RoleId == 1 {
|
||||
book.RoleName = "管理员"
|
||||
book.RoleName = i18n.Tr(lang, "common.administrator")
|
||||
} else if book.RoleId == 2 {
|
||||
book.RoleName = "编辑者"
|
||||
book.RoleName = i18n.Tr(lang, "common.editor")
|
||||
} else if book.RoleId == 3 {
|
||||
book.RoleName = "观察者"
|
||||
book.RoleName = i18n.Tr(lang, "common.observer")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -631,7 +632,7 @@ WHERE (relationship_id > 0 OR book.privately_owned = 0 or team.team_member_id >
|
||||
}
|
||||
|
||||
// ReleaseContent 批量发布文档
|
||||
func (book *Book) ReleaseContent(bookId int) {
|
||||
func (book *Book) ReleaseContent(bookId int, lang string) {
|
||||
releaseQueue <- bookId
|
||||
once.Do(func() {
|
||||
go func() {
|
||||
@@ -652,6 +653,7 @@ func (book *Book) ReleaseContent(bookId int) {
|
||||
}
|
||||
for _, item := range docs {
|
||||
item.BookId = bookId
|
||||
item.Lang = lang
|
||||
_ = item.ReleaseContent()
|
||||
}
|
||||
|
||||
@@ -678,8 +680,8 @@ func (book *Book) ResetDocumentNumber(bookId int) {
|
||||
}
|
||||
}
|
||||
|
||||
//导入项目
|
||||
func (book *Book) ImportBook(zipPath string) error {
|
||||
// 导入zip项目
|
||||
func (book *Book) ImportBook(zipPath string, lang string) error {
|
||||
if !filetil.FileExists(zipPath) {
|
||||
return errors.New("文件不存在 => " + zipPath)
|
||||
}
|
||||
@@ -972,7 +974,79 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
book.Description = "【项目导入存在错误:" + err.Error() + "】"
|
||||
}
|
||||
logs.Info("项目导入完毕 => ", book.BookName)
|
||||
book.ReleaseContent(book.BookId)
|
||||
book.ReleaseContent(book.BookId, lang)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/converter"
|
||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||
@@ -70,6 +71,7 @@ type BookResult struct {
|
||||
IsDisplayComment bool `json:"is_display_comment"`
|
||||
IsDownload bool `json:"is_download"`
|
||||
AutoSave bool `json:"auto_save"`
|
||||
Lang string
|
||||
}
|
||||
|
||||
func NewBookResult() *BookResult {
|
||||
@@ -85,6 +87,11 @@ func (m *BookResult) String() string {
|
||||
return string(ret)
|
||||
}
|
||||
|
||||
func (m *BookResult) SetLang(lang string) *BookResult {
|
||||
m.Lang = lang
|
||||
return m
|
||||
}
|
||||
|
||||
// 根据项目标识查询项目以及指定用户权限的信息.
|
||||
func (m *BookResult) FindByIdentify(identify string, memberId int) (*BookResult, error) {
|
||||
if identify == "" || memberId <= 0 {
|
||||
@@ -131,13 +138,13 @@ func (m *BookResult) FindByIdentify(identify string, memberId int) (*BookResult,
|
||||
}
|
||||
|
||||
if m.RoleId == conf.BookFounder {
|
||||
m.RoleName = "创始人"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.creator")
|
||||
} else if m.RoleId == conf.BookAdmin {
|
||||
m.RoleName = "管理员"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.administrator")
|
||||
} else if m.RoleId == conf.BookEditor {
|
||||
m.RoleName = "编辑者"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.editor")
|
||||
} else if m.RoleId == conf.BookObserver {
|
||||
m.RoleName = "观察者"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.observer")
|
||||
}
|
||||
|
||||
doc := NewDocument()
|
||||
|
||||
@@ -3,6 +3,8 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/beego/i18n"
|
||||
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
@@ -44,6 +46,8 @@ type Document struct {
|
||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||
ViewCount int `orm:"column(view_count);type(int)" json:"view_count"`
|
||||
AttachList []*Attachment `orm:"-" json:"attach"`
|
||||
//i18n
|
||||
Lang string `orm:"-"`
|
||||
}
|
||||
|
||||
// 多字段唯一键
|
||||
@@ -276,7 +280,7 @@ func (item *Document) Processor() *Document {
|
||||
//处理附件
|
||||
attachList, err := NewAttachment().FindListByDocumentId(item.DocumentId)
|
||||
if err == nil && len(attachList) > 0 {
|
||||
content := bytes.NewBufferString("<div class=\"attach-list\"><strong>附件</strong><ul>")
|
||||
content := bytes.NewBufferString("<div class=\"attach-list\"><strong>" + i18n.Tr(item.Lang, "doc.attachment") + "</strong><ul>")
|
||||
for _, attach := range attachList {
|
||||
if strings.HasPrefix(attach.HttpPath, "/") {
|
||||
attach.HttpPath = strings.TrimSuffix(conf.BaseUrl, "/") + attach.HttpPath
|
||||
@@ -306,7 +310,7 @@ func (item *Document) Processor() *Document {
|
||||
docCreator, err := NewMember().Find(item.MemberId, "real_name", "account")
|
||||
release := "<div class=\"wiki-bottom\">"
|
||||
|
||||
release += "作者:"
|
||||
release += i18n.Tr(item.Lang, "doc.ft_author")
|
||||
if err == nil && docCreator != nil {
|
||||
if docCreator.RealName != "" {
|
||||
release += docCreator.RealName
|
||||
@@ -314,19 +318,19 @@ func (item *Document) Processor() *Document {
|
||||
release += docCreator.Account
|
||||
}
|
||||
}
|
||||
release += " 创建时间:" + item.CreateTime.Local().Format("2006-01-02 15:04") + "<br>"
|
||||
release += " " + i18n.Tr(item.Lang, "doc.ft_create_time") + item.CreateTime.Local().Format("2006-01-02 15:04") + "<br>"
|
||||
|
||||
if item.ModifyAt > 0 {
|
||||
docModify, err := NewMember().Find(item.ModifyAt, "real_name", "account")
|
||||
if err == nil {
|
||||
if docModify.RealName != "" {
|
||||
release += "最后编辑:" + docModify.RealName
|
||||
release += i18n.Tr(item.Lang, "doc.ft_last_editor") + docModify.RealName
|
||||
} else {
|
||||
release += "最后编辑:" + docModify.Account
|
||||
release += i18n.Tr(item.Lang, "doc.ft_last_editor") + docModify.Account
|
||||
}
|
||||
}
|
||||
}
|
||||
release += " 更新时间:" + item.ModifyTime.Local().Format("2006-01-02 15:04") + "<br>"
|
||||
release += " " + i18n.Tr(item.Lang, "doc.ft_update_time") + item.ModifyTime.Local().Format("2006-01-02 15:04") + "<br>"
|
||||
release += "</div>"
|
||||
|
||||
if selector := docQuery.Find("div.markdown-article").First(); selector.Size() > 0 {
|
||||
@@ -335,7 +339,7 @@ func (item *Document) Processor() *Document {
|
||||
selector.First().AppendHtml(release)
|
||||
}
|
||||
}
|
||||
cdnimg,_ := web.AppConfig.String("cdnimg")
|
||||
cdnimg, _ := web.AppConfig.String("cdnimg")
|
||||
|
||||
docQuery.Find("img").Each(func(i int, selection *goquery.Selection) {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
)
|
||||
@@ -44,6 +45,8 @@ type Member struct {
|
||||
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
|
||||
CreateAt int `orm:"type(int);column(create_at)" json:"create_at"`
|
||||
LastLoginTime time.Time `orm:"type(datetime);column(last_login_time);null" json:"last_login_time"`
|
||||
//i18n
|
||||
Lang string `orm:"-"`
|
||||
}
|
||||
|
||||
// TableName 获取对应数据库表名.
|
||||
@@ -327,11 +330,11 @@ func (m *Member) Find(id int, cols ...string) (*Member, error) {
|
||||
|
||||
func (m *Member) ResolveRoleName() {
|
||||
if m.Role == conf.MemberSuperRole {
|
||||
m.RoleName = "超级管理员"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.administrator")
|
||||
} else if m.Role == conf.MemberAdminRole {
|
||||
m.RoleName = "管理员"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.editor")
|
||||
} else if m.Role == conf.MemberGeneralRole {
|
||||
m.RoleName = "普通用户"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.obverser")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -54,19 +55,19 @@ func (m *MemberRelationshipResult) FromMember(member *Member) *MemberRelationshi
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MemberRelationshipResult) ResolveRoleName() *MemberRelationshipResult {
|
||||
func (m *MemberRelationshipResult) ResolveRoleName(lang string) *MemberRelationshipResult {
|
||||
if m.RoleId == conf.BookAdmin {
|
||||
m.RoleName = "管理者"
|
||||
m.RoleName = i18n.Tr(lang, "common.administrator")
|
||||
} else if m.RoleId == conf.BookEditor {
|
||||
m.RoleName = "编辑者"
|
||||
m.RoleName = i18n.Tr(lang, "common.editor")
|
||||
} else if m.RoleId == conf.BookObserver {
|
||||
m.RoleName = "观察者"
|
||||
m.RoleName = i18n.Tr(lang, "common.obverser")
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// 根据项目ID查询用户
|
||||
func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageSize int) ([]*MemberRelationshipResult, int, error) {
|
||||
func (m *MemberRelationshipResult) FindForUsersByBookId(lang string, bookId, pageIndex, pageSize int) ([]*MemberRelationshipResult, int, error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
var members []*MemberRelationshipResult
|
||||
@@ -92,7 +93,7 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageS
|
||||
}
|
||||
|
||||
for _, item := range members {
|
||||
item.ResolveRoleName()
|
||||
item.ResolveRoleName(lang)
|
||||
}
|
||||
return members, total_count, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -18,6 +19,7 @@ type TeamMember struct {
|
||||
Account string `orm:"-" json:"account"`
|
||||
RealName string `orm:"-" json:"real_name"`
|
||||
Avatar string `orm:"-" json:"avatar"`
|
||||
Lang string `orm:"-"`
|
||||
}
|
||||
|
||||
// TableName 获取对应数据库表名.
|
||||
@@ -46,6 +48,11 @@ func NewTeamMember() *TeamMember {
|
||||
return &TeamMember{}
|
||||
}
|
||||
|
||||
func (m *TeamMember) SetLang(lang string) *TeamMember {
|
||||
m.Lang = lang
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *TeamMember) First(id int, cols ...string) (*TeamMember, error) {
|
||||
if id <= 0 {
|
||||
return nil, errors.New("参数错误")
|
||||
@@ -173,6 +180,7 @@ func (m *TeamMember) FindToPager(teamId, pageIndex, pageSize int) (list []*TeamM
|
||||
|
||||
//将来优化
|
||||
for _, item := range list {
|
||||
item.Lang = m.Lang
|
||||
item.Include()
|
||||
}
|
||||
return
|
||||
@@ -187,13 +195,13 @@ func (m *TeamMember) Include() *TeamMember {
|
||||
m.Avatar = member.Avatar
|
||||
}
|
||||
if m.RoleId == 0 {
|
||||
m.RoleName = "创始人"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.creator") //"创始人"
|
||||
} else if m.RoleId == 1 {
|
||||
m.RoleName = "管理员"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.administrator") //"管理员"
|
||||
} else if m.RoleId == 2 {
|
||||
m.RoleName = "编辑者"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.editor") //"编辑者"
|
||||
} else if m.RoleId == 3 {
|
||||
m.RoleName = "观察者"
|
||||
m.RoleName = i18n.Tr(m.Lang, "common.observer") //"观察者"
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user