解决导出文档失败的BUG

This commit is contained in:
Minho
2018-03-30 17:21:16 +08:00
parent 98e93a19d5
commit 4a6494e9f8
4 changed files with 59 additions and 28 deletions

View File

@@ -223,7 +223,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
docxpath := filepath.Join(outputPath, "book.docx")
//先将转换的文件储存到临时目录
tempOutputPath := filepath.Join(os.TempDir(), sessionId, m.Identify) //filepath.Abs(filepath.Join("cache", sessionId))
tempOutputPath := filepath.Join(os.TempDir(), sessionId, m.Identify,"source") //filepath.Abs(filepath.Join("cache", sessionId))
os.MkdirAll(outputPath, 0766)
os.MkdirAll(tempOutputPath, 0766)
@@ -366,21 +366,23 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
eBookConverter := &converter.Converter{
BasePath: tempOutputPath,
OutputPath: strings.TrimSuffix(tempOutputPath, "sources"),
OutputPath: filepath.Join(strings.TrimSuffix(tempOutputPath, "source"),"output"),
Config: ebookConfig,
Debug: true,
}
os.MkdirAll(eBookConverter.OutputPath,0766)
if err := eBookConverter.Convert(); err != nil {
beego.Error("转换文件错误:" + m.BookName + " => " + err.Error())
return convertBookResult, err
}
beego.Info("文档转换完成:" + m.BookName)
filetil.CopyFile(mobipath, filepath.Join(tempOutputPath, "output", "book.mobi"))
filetil.CopyFile(pdfpath, filepath.Join(tempOutputPath, "output", "book.pdf"))
filetil.CopyFile(epubpath, filepath.Join(tempOutputPath, "output", "book.epub"))
filetil.CopyFile(docxpath, filepath.Join(tempOutputPath, "output", "book.docx"))
filetil.CopyFile(filepath.Join(eBookConverter.OutputPath,"output", "book.mobi"),mobipath,)
filetil.CopyFile(filepath.Join(eBookConverter.OutputPath,"output", "book.pdf"),pdfpath)
filetil.CopyFile(filepath.Join(eBookConverter.OutputPath,"output", "book.epub"),epubpath)
filetil.CopyFile(filepath.Join(eBookConverter.OutputPath,"output", "book.docx"),docxpath)
convertBookResult.MobiPath = mobipath
convertBookResult.PDFPath = pdfpath

View File

@@ -87,6 +87,14 @@ func (m *Document) InsertOrUpdate(cols ...string) error {
if m.DocumentId > 0 {
_, err = o.Update(m, cols...)
} else {
if m.Identify == "" {
book := NewBook()
identify := "docs"
if err := o.QueryTable(book.TableNameWithPrefix()).One(book,"identify");err == nil {
identify = book.Identify
}
m.Identify = fmt.Sprintf("%s-%d%d",identify,m.BookId,time.Now().Unix())
}
_, err = o.Insert(m)
NewBook().ResetDocumentNumber(m.BookId)
}