mirror of https://github.com/mindoc-org/mindoc.git
增加项目导出目录配置,可自定义导出的缓存目录
parent
449fecd4eb
commit
ebf36e6146
|
@ -13,7 +13,7 @@ beegoserversessionkey=123456
|
|||
########Session储存方式##############
|
||||
#以文件方式储存
|
||||
sessionprovider=file
|
||||
sessionproviderconfig=./logs
|
||||
sessionproviderconfig=./runtime/session
|
||||
#以redis方式储存
|
||||
#sessionprovider=redis
|
||||
#sessionproviderconfig=127.0.0.1:6379
|
||||
|
@ -73,14 +73,19 @@ mail_expired=30
|
|||
#加密类型NONE 无认证、SSL 加密、LOGIN 普通用户登录
|
||||
secure=LOGIN
|
||||
|
||||
###############配置PDF生成工具地址###################
|
||||
###############配置导出项目###################
|
||||
#同一个项目同时运行导出程序的并行数量,取值1-4之间,取值越大导出速度越快,越占用资源
|
||||
export_process_num=1
|
||||
|
||||
#并发导出的项目限制,指同一时间限制的导出项目数量,如果为0则不限制。设置的越大,越占用资源
|
||||
export_limit_num=1
|
||||
|
||||
#指同时等待导出的任务数量
|
||||
export_queue_limit_num=100
|
||||
|
||||
#导出项目的缓存目录配置
|
||||
export_output_path=./runtime/cache
|
||||
|
||||
###############配置CDN加速##################
|
||||
cdn=
|
||||
cdnjs=
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/astaxie/beego"
|
||||
"strconv"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// 登录用户的Session名
|
||||
|
@ -65,7 +66,7 @@ var (
|
|||
var (
|
||||
ConfigurationFile = "./conf/app.conf"
|
||||
WorkingDirectory = "./"
|
||||
LogFile = "./logs"
|
||||
LogFile = "./runtime/logs"
|
||||
BaseUrl = ""
|
||||
)
|
||||
|
||||
|
@ -90,6 +91,7 @@ func GetTokenSize() int {
|
|||
|
||||
//获取默认文档封面.
|
||||
func GetDefaultCover() string {
|
||||
|
||||
return URLForWithCdnImage(beego.AppConfig.DefaultString("cover", "/static/images/book.jpg"))
|
||||
}
|
||||
|
||||
|
@ -162,6 +164,12 @@ func GetExportQueueLimitNum() int {
|
|||
}
|
||||
return exportQueueLimitNum
|
||||
}
|
||||
//默认导出项目的缓存目录
|
||||
func GetExportOutputPath() string {
|
||||
exportOutputPath := filepath.Join(beego.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory,"cache")),"books")
|
||||
|
||||
return exportOutputPath
|
||||
}
|
||||
|
||||
//判断是否是允许商城的文件类型.
|
||||
func IsAllowUploadFileExt(ext string) bool {
|
||||
|
|
|
@ -707,7 +707,7 @@ func (c *BookController) Release() {
|
|||
models.NewBook().ReleaseContent(bookId)
|
||||
|
||||
//当文档发布后,需要删除已缓存的转换项目
|
||||
outputPath := filepath.Join(beego.AppConfig.DefaultString("book_output_path", "cache"), strconv.Itoa(bookId))
|
||||
outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(bookId))
|
||||
os.RemoveAll(outputPath)
|
||||
|
||||
}(identify)
|
||||
|
|
|
@ -858,7 +858,7 @@ func (c *DocumentController) Export() {
|
|||
return
|
||||
}
|
||||
|
||||
outputPath := filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(bookResult.BookId))
|
||||
outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(bookResult.BookId))
|
||||
|
||||
pdfpath := filepath.Join(outputPath, "book.pdf")
|
||||
epubpath := filepath.Join(outputPath, "book.epub")
|
||||
|
@ -1092,7 +1092,7 @@ func (c *DocumentController) DeleteHistory() {
|
|||
|
||||
c.JsonResult(0, "ok")
|
||||
}
|
||||
|
||||
//通过文档历史恢复文档
|
||||
func (c *DocumentController) RestoreHistory() {
|
||||
c.Prepare()
|
||||
|
||||
|
|
|
@ -193,13 +193,11 @@ func (convert *Converter) Convert() (err error) {
|
|||
group := sync.WaitGroup{}
|
||||
for {
|
||||
action, isClosed := <-convert.process
|
||||
fmt.Println(action,isClosed)
|
||||
if action == nil && !isClosed {
|
||||
break;
|
||||
}
|
||||
group.Add(1)
|
||||
<- convert.limitChan
|
||||
fmt.Println("正在处理")
|
||||
go func(group *sync.WaitGroup) {
|
||||
action()
|
||||
group.Done()
|
||||
|
|
|
@ -216,9 +216,12 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
|
|||
|
||||
//后台转换
|
||||
func BackgroupConvert(sessionId string,bookResult *BookResult){
|
||||
exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() {
|
||||
err := exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() {
|
||||
bookResult.Converter(sessionId)
|
||||
})
|
||||
if err != nil {
|
||||
beego.Error("将导出任务加入任务队列失败 -> ",err)
|
||||
}
|
||||
exportLimitWorkerChannel.Start()
|
||||
}
|
||||
|
||||
|
@ -227,7 +230,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
|||
|
||||
convertBookResult := ConvertBookResult{}
|
||||
|
||||
outputPath := filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(m.BookId))
|
||||
outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(m.BookId))
|
||||
viewPath := beego.BConfig.WebConfig.ViewsPath
|
||||
|
||||
pdfpath := filepath.Join(outputPath, "book.pdf")
|
||||
|
|
Loading…
Reference in New Issue