Skip to content

Commit 5f1ebc1

Browse files
committed
文档转换问题处理
1 parent 0631543 commit 5f1ebc1

File tree

6 files changed

+23
-17
lines changed

6 files changed

+23
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ DocHub
5555
sitemap
5656
sitemap.xml
5757
*_test.go
58-
store
58+
store
59+
*.sh

TODO.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828

2929
## DocHub v2.3
30-
- [ ] `文档管理`文档删除的错误
30+
- [ ] 用户注册和登录成功之后的跳转优化
31+
- [ ] 图片裁剪质量优化
32+
- [x] `文档管理`文档删除的错误
3133
- [x] 移除对zoneinfo.zip的依赖
3234
- [x] calibre 文档转换优化
3335
- [x] 解决程序不支持utf8mb4数据库字符编码问题(ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes),索引字段太长导致

controllers/AdminControllers/DocController.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func (this *DocController) Recycle() {
111111
p = helper.NumberRange(p, 1, 10000)
112112
listRows := this.Sys.ListRows
113113
this.Data["Lists"], _, _ = models.NewDocumentRecycle().RecycleList(p, listRows)
114-
fmt.Println(this.Data["Lists"])
115114
this.Data["Tab"] = "recycle"
116115
this.TplName = "recycle.html"
117116
}

helper/convert.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func OfficeToPDF(file string) (err error) {
7070
//非office文档(.txt,.mobi,.epub)转pdf文档
7171
func ConvertByCalibre(file string, ext ...string) (resFile string, err error) {
7272
//calibre := beego.AppConfig.DefaultString("calibre", "ebook-convert")
73-
e := ".pdf"
73+
e := ExtPDF
7474
if len(ext) > 0 {
7575
e = ext[0]
7676
}
@@ -81,20 +81,24 @@ func ConvertByCalibre(file string, ext ...string) (resFile string, err error) {
8181
args := []string{
8282
file,
8383
resFile,
84-
"--paper-size", "a4",
85-
"--pdf-default-font-size", "16",
86-
"--pdf-page-margin-bottom", "36",
87-
"--pdf-page-margin-left", "36",
88-
"--pdf-page-margin-right", "36",
89-
"--pdf-page-margin-top", "36",
84+
}
85+
if e == ExtPDF {
86+
args = append(args,
87+
"--paper-size", "a4",
88+
"--pdf-default-font-size", "16",
89+
"--pdf-page-margin-bottom", "36",
90+
"--pdf-page-margin-left", "36",
91+
"--pdf-page-margin-right", "36",
92+
"--pdf-page-margin-top", "36",
93+
)
9094
}
9195
cmd := exec.Command(calibre, args...)
9296
if strings.HasPrefix(calibre, "sudo") {
9397
calibre = strings.TrimPrefix(calibre, "sudo")
9498
args = append([]string{calibre}, args...)
9599
cmd = exec.Command("sudo", args...)
96100
}
97-
Logger.Debug("calibre文档转换:%v", args)
101+
Logger.Debug("calibre文档转换:%v %v", calibre, strings.Join(args, " "))
98102
time.AfterFunc(60*time.Minute, func() {
99103
if cmd.Process != nil {
100104
cmd.Process.Kill()

models/UserModel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (this *User) CanDownloadFile(uid, docId int) (urlStr string, err error) {
295295
return
296296
}
297297
} else {
298-
logDown.Log = fmt.Sprintf("在免费期限内,下载同一篇文档(%v)免费", doc.Title)
298+
logDown.Log = fmt.Sprintf("在免费期限内,下载同一篇文档《%v》免费", doc.Title)
299299
}
300300

301301
if _, err = o.Insert(&logDown); err != nil {

models/Utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,13 @@ func DocumentConvert(tmpFile string, fileMD5 string, page ...int) (err error) {
371371
beego.Debug("存储svg文件", svg, "==>", save)
372372
}
373373

374-
errCompress := helper.CompressBySVGO(svg, svg)
375-
if errCompress != nil {
376-
helper.Logger.Error("SVGO压缩SVG失败:%v", errCompress.Error())
374+
err = helper.CompressBySVGO(svg, svg)
375+
if err != nil {
376+
helper.Logger.Error("SVGO压缩SVG失败:%v", err.Error())
377377
}
378378
if clientPublic.CanGZIP {
379-
if errCompress = helper.CompressByGzip(svg); err != nil {
380-
helper.Logger.Error("GZIP压缩SVG失败:%v", errCompress.Error())
379+
if err = helper.CompressByGzip(svg); err != nil {
380+
helper.Logger.Error("GZIP压缩SVG失败:%v", err.Error())
381381
} else {
382382
headers = append(headers, helper.HeaderGzip)
383383
}

0 commit comments

Comments
 (0)