mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-10-25 02:44:52 +08:00
chore!(all): attempt to update beego to v2
BREAKING CHANGE: beego has update to v2, and this version of mindoc IS NOT TESTED AND STABLE!!!
This commit is contained in:
@@ -14,9 +14,10 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/adapter"
|
||||
"github.com/beego/beego/v2/adapter/logs"
|
||||
"github.com/beego/beego/v2/adapter/orm"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/converter"
|
||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||
@@ -97,7 +98,7 @@ func (m *BookResult) FindByIdentify(identify string, memberId int) (*BookResult,
|
||||
err := NewBook().QueryTable().Filter("identify", identify).One(&book)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("获取项目失败 ->", err)
|
||||
logs.Error("获取项目失败 ->", err)
|
||||
return m, err
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
|
||||
}
|
||||
|
||||
if m.ItemId > 0 {
|
||||
if item,err := NewItemsets().First(m.ItemId); err == nil {
|
||||
if item, err := NewItemsets().First(m.ItemId); err == nil {
|
||||
m.ItemName = item.ItemName
|
||||
}
|
||||
}
|
||||
@@ -240,7 +241,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
|
||||
func BackgroundConvert(sessionId string, bookResult *BookResult) error {
|
||||
|
||||
if err := converter.CheckConvertCommand(); err != nil {
|
||||
beego.Error("检查转换程序失败 -> ", err)
|
||||
logs.Error("检查转换程序失败 -> ", err)
|
||||
return err
|
||||
}
|
||||
err := exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() {
|
||||
@@ -249,7 +250,7 @@ func BackgroundConvert(sessionId string, bookResult *BookResult) error {
|
||||
|
||||
if err != nil {
|
||||
|
||||
beego.Error("将导出任务加入任务队列失败 -> ", err)
|
||||
logs.Error("将导出任务加入任务队列失败 -> ", err)
|
||||
return err
|
||||
}
|
||||
exportLimitWorkerChannel.Start()
|
||||
@@ -262,7 +263,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
convertBookResult := ConvertBookResult{}
|
||||
|
||||
outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(m.BookId))
|
||||
viewPath := beego.BConfig.WebConfig.ViewsPath
|
||||
viewPath := web.BConfig.WebConfig.ViewsPath
|
||||
|
||||
pdfpath := filepath.Join(outputPath, "book.pdf")
|
||||
epubpath := filepath.Join(outputPath, "book.epub")
|
||||
@@ -272,18 +273,18 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
//先将转换的文件储存到临时目录
|
||||
tempOutputPath := filepath.Join(os.TempDir(), sessionId, m.Identify, "source") //filepath.Abs(filepath.Join("cache", sessionId))
|
||||
|
||||
sourceDir := strings.TrimSuffix(tempOutputPath, "source");
|
||||
sourceDir := strings.TrimSuffix(tempOutputPath, "source")
|
||||
if filetil.FileExists(sourceDir) {
|
||||
if err := os.RemoveAll(sourceDir); err != nil {
|
||||
beego.Error("删除临时目录失败 ->", sourceDir, err)
|
||||
logs.Error("删除临时目录失败 ->", sourceDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(outputPath, 0766); err != nil {
|
||||
beego.Error("创建目录失败 -> ", outputPath, err)
|
||||
logs.Error("创建目录失败 -> ", outputPath, err)
|
||||
}
|
||||
if err := os.MkdirAll(tempOutputPath, 0766); err != nil {
|
||||
beego.Error("创建目录失败 -> ", tempOutputPath, err)
|
||||
logs.Error("创建目录失败 -> ", tempOutputPath, err)
|
||||
}
|
||||
os.MkdirAll(filepath.Join(tempOutputPath, "Images"), 0755)
|
||||
|
||||
@@ -359,7 +360,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
}
|
||||
|
||||
if tempOutputPath, err = filepath.Abs(tempOutputPath); err != nil {
|
||||
beego.Error("导出目录配置错误:" + err.Error())
|
||||
logs.Error("导出目录配置错误:" + err.Error())
|
||||
return convertBookResult, err
|
||||
}
|
||||
|
||||
@@ -373,7 +374,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := beego.ExecuteViewPathTemplate(&buf, "document/export.tpl", viewPath, map[string]interface{}{"Model": m, "Lists": item, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
if err := adapter.ExecuteViewPathTemplate(&buf, "document/export.tpl", viewPath, map[string]interface{}{"Model": m, "Lists": item, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
return convertBookResult, err
|
||||
}
|
||||
html := buf.String()
|
||||
@@ -396,7 +397,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
if strings.HasPrefix(src, "/") {
|
||||
spath := filepath.Join(conf.WorkingDirectory, src)
|
||||
if filetil.CopyFile(spath, filepath.Join(tempOutputPath, dstSrcString)); err != nil {
|
||||
beego.Error("复制图片失败 -> ", err, src)
|
||||
logs.Error("复制图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -415,15 +416,15 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
if body, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||
//encodeString = base64.StdEncoding.EncodeToString(body)
|
||||
if err := ioutil.WriteFile(filepath.Join(tempOutputPath, dstSrcString), body, 0755); err != nil {
|
||||
beego.Error("下载图片失败 -> ", err, src)
|
||||
logs.Error("下载图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
beego.Error("下载图片失败 -> ", err, src)
|
||||
logs.Error("下载图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
beego.Error("下载图片失败 -> ", err, src)
|
||||
logs.Error("下载图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -446,27 +447,27 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
}
|
||||
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "css", "kancloud.css"), filepath.Join(tempOutputPath, "styles", "css", "kancloud.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/css/kancloud.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/css/kancloud.css", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "css", "export.css"), filepath.Join(tempOutputPath, "styles", "css", "export.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/css/export.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/css/export.css", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "css", "editormd.preview.css"), filepath.Join(tempOutputPath, "styles", "editor.md", "css", "editormd.preview.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/editor.md/css/editormd.preview.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/editor.md/css/editormd.preview.css", err)
|
||||
}
|
||||
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "css", "markdown.preview.css"), filepath.Join(tempOutputPath, "styles", "css", "markdown.preview.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/css/markdown.preview.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/css/markdown.preview.css", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "lib", "highlight", "styles", "github.css"), filepath.Join(tempOutputPath, "styles", "css", "github.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/editor.md/lib/highlight/styles/github.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/editor.md/lib/highlight/styles/github.css", err)
|
||||
}
|
||||
|
||||
if err := filetil.CopyDir(filepath.Join(conf.WorkingDirectory, "static", "font-awesome"), filepath.Join(tempOutputPath, "styles", "font-awesome")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/font-awesome", err)
|
||||
logs.Error("复制CSS样式出错 -> static/font-awesome", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "lib", "mermaid", "mermaid.css"), filepath.Join(tempOutputPath, "styles", "css", "mermaid.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/editor.md/lib/mermaid/mermaid.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/editor.md/lib/mermaid/mermaid.css", err)
|
||||
}
|
||||
|
||||
eBookConverter := &converter.Converter{
|
||||
@@ -480,22 +481,22 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
os.MkdirAll(eBookConverter.OutputPath, 0766)
|
||||
|
||||
if err := eBookConverter.Convert(); err != nil {
|
||||
beego.Error("转换文件错误:" + m.BookName + " -> " + err.Error())
|
||||
logs.Error("转换文件错误:" + m.BookName + " -> " + err.Error())
|
||||
return convertBookResult, err
|
||||
}
|
||||
beego.Info("文档转换完成:" + m.BookName)
|
||||
logs.Info("文档转换完成:" + m.BookName)
|
||||
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.mobi"), mobipath, ); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.mobi"), err)
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.mobi"), mobipath); err != nil {
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.mobi"), err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.pdf"), pdfpath); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.pdf"), err)
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.pdf"), err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.epub"), epubpath); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.epub"), err)
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.epub"), err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.docx"), docxpath); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.docx"), err)
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.docx"), err)
|
||||
}
|
||||
|
||||
convertBookResult.MobiPath = mobipath
|
||||
@@ -525,7 +526,7 @@ func (m *BookResult) ExportMarkdown(sessionId string) (string, error) {
|
||||
}
|
||||
|
||||
if err := ziptil.Compress(outputPath, tempOutputPath); err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return "", err
|
||||
}
|
||||
return outputPath, nil
|
||||
@@ -540,7 +541,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
_, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id", parentId).All(&docs)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return err
|
||||
}
|
||||
for _, doc := range docs {
|
||||
@@ -548,7 +549,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
subDocCount, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("parent_id", doc.DocumentId).Count()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -623,13 +624,13 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
if id, err := strconv.Atoi(docIdentify); err == nil && id > 0 {
|
||||
err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("document_id", id).One(tempDoc, "identify", "parent_id", "document_id")
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
return link
|
||||
}
|
||||
} else {
|
||||
err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("identify", docIdentify).One(tempDoc, "identify", "parent_id", "document_id")
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
return link
|
||||
}
|
||||
}
|
||||
@@ -644,7 +645,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
relative = strings.TrimSuffix(strings.TrimPrefix(relative, "/"), "/")
|
||||
repeat = strings.Count(relative, "/") + 1
|
||||
}
|
||||
beego.Info(repeat, "|", relative, "|", p, "|", baseDir)
|
||||
logs.Info(repeat, "|", relative, "|", p, "|", baseDir)
|
||||
tempLink = strings.Repeat("../", repeat) + tempLink
|
||||
|
||||
link = strings.TrimSuffix(link, originalLink+")") + tempLink + ")"
|
||||
@@ -658,7 +659,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
markdown = "# " + doc.DocumentName + "\n"
|
||||
}
|
||||
if err := ioutil.WriteFile(docPath, []byte(markdown), 0644); err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -679,7 +680,7 @@ func recursiveJoinDocumentIdentify(parentDocId int, identify string) string {
|
||||
err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("document_id", parentDocId).One(doc, "identify", "parent_id", "document_id")
|
||||
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
return identify
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user