Skip to content

Commit 2384bfe

Browse files
committed
如果未安装相关模块,则屏蔽相关功能
1 parent 2e9d0fc commit 2384bfe

File tree

6 files changed

+88
-50
lines changed

6 files changed

+88
-50
lines changed

controllers/BookController.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func (this *BookController) Index() {
9393
} else {
9494
this.Data["Result"] = template.JS(string(b))
9595
}
96+
installedDependencies := utils.GetInstalledDependencies()
97+
for _, item := range installedDependencies {
98+
this.Data[item.Name+"_is_installed"] = item.IsInstalled
99+
}
96100
}
97101

98102
//收藏书籍
@@ -192,6 +196,10 @@ func (this *BookController) Setting() {
192196
this.Data["Cates"], _ = new(models.Category).GetCates(-1, 1)
193197
this.Data["Model"] = book
194198
this.TplName = "book/setting.html"
199+
installedDependencies := utils.GetInstalledDependencies()
200+
for _, item := range installedDependencies {
201+
this.Data[item.Name+"_is_installed"] = item.IsInstalled
202+
}
195203
}
196204

197205
// SaveBook 保存书籍信息

controllers/DocumentController.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,10 @@ func (this *DocumentController) Edit() {
557557
}
558558
}
559559
this.Data["BaiDuMapKey"] = beego.AppConfig.DefaultString("baidumapkey", "")
560-
560+
installedDependencies := utils.GetInstalledDependencies()
561+
for _, item := range installedDependencies {
562+
this.Data[item.Name+"_is_installed"] = item.IsInstalled
563+
}
561564
}
562565

563566
//创建一个文档.

utils/dependency.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/astaxie/beego"
77
)
88

9-
var installedDependencies = make(map[string]installedDependency)
9+
var installedDependencies []installedDependency
1010

1111
type installedDependency struct {
1212
Name string // 依赖名称
@@ -20,7 +20,7 @@ func init() {
2020
go checkInstalledDependencyData()
2121
}
2222

23-
func GetInstalledDependencies() map[string]installedDependency {
23+
func GetInstalledDependencies() []installedDependency {
2424
return installedDependencies
2525
}
2626

@@ -35,52 +35,52 @@ func checkInstalledDependencyData() {
3535
if err = IsInstalledCalibre("ebook-convert"); err != nil {
3636
errCalibre = err.Error()
3737
}
38-
installedDependencies[nameCalibre] = installedDependency{
38+
installedDependencies = append(installedDependencies, installedDependency{
3939
Name: nameCalibre,
4040
IsInstalled: err == nil,
4141
Error: errCalibre,
4242
Message: "calibre 用于将书籍转换成PDF、epub和mobi ==> <a class='text-danger' target='_blank' href='https://www.bookstack.cn/read/help/Ubuntu.md'>安装教程</a>。如果未安装该模块,则无法生成电子书和提供电子书下载。",
4343
CheckedAt: time.Now().Format(dateLayout),
44-
}
44+
})
4545

4646
errGit := "-"
4747
nameGit := "git"
4848
if err = IsInstalledGit(); err != nil {
4949
errGit = err.Error()
5050
}
51-
installedDependencies[nameGit] = installedDependency{
51+
installedDependencies = append(installedDependencies, installedDependency{
5252
Name: nameGit,
5353
IsInstalled: err == nil,
5454
Error: errGit,
5555
Message: "git,用于git clone方式导入项目。如果未安装该模块,则无法使用该方式导入项目。",
5656
CheckedAt: time.Now().Format(dateLayout),
57-
}
57+
})
5858

5959
errChrome := "-"
6060
nameChrome := "chrome"
6161
if err = IsInstalledChrome(beego.AppConfig.DefaultString("chrome", "chrome")); err != nil {
6262
errChrome = err.Error()
6363
}
64-
installedDependencies[nameChrome] = installedDependency{
64+
installedDependencies = append(installedDependencies, installedDependency{
6565
Name: nameChrome,
6666
IsInstalled: err == nil,
6767
Error: errChrome,
6868
Message: "chrome浏览器,即谷歌浏览器,或者chromium-browser,用于渲染markdown内容为HTML。",
6969
CheckedAt: time.Now().Format(dateLayout),
70-
}
70+
})
7171

7272
namePuppeteer := "puppeteer"
7373
errPuppeteer := "-"
7474
if err = IsInstalledPuppetter(); err != nil {
7575
errPuppeteer = err.Error()
7676
}
77-
installedDependencies[namePuppeteer] = installedDependency{
78-
Name: "puppeteer",
77+
installedDependencies = append(installedDependencies, installedDependency{
78+
Name: namePuppeteer,
7979
IsInstalled: err == nil,
8080
Error: errPuppeteer,
8181
Message: "puppeteer, node.js的模块,用于将markdown渲染为HTML以及生成电子书封面。 <a class='text-danger' target='_blank' href='https://www.bookstack.cn/read/help/Ubuntu.md'>安装教程</a>",
8282
CheckedAt: time.Now().Format(dateLayout),
83-
}
83+
})
8484
}
8585

8686
// IsInstalledPuppetter 是否安装了puppeteer

views/book/index.html

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
</div>
8585

8686
<div class="clearfix"></div>
87+
{{if $.calibre_is_installed}}
8788
<div class="row ebook-stats">
8889
<div class="col-xs-6 col-sm-3" v-for="(stats,ext) in stats[item.book_id]">
8990
<div class="progress">
@@ -107,6 +108,7 @@
107108
</div>
108109
</div>
109110
</div>
111+
{{end}}
110112
</div>
111113
<div class="info hidden-xs">
112114
<span title="创建者" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-user"></i> ${item.create_name}</span>
@@ -129,45 +131,56 @@
129131
<div class="btns">
130132
<a :href="'{{urlfor "DocumentController.Index" ":key" ""}}' + item.identify" title="查看书籍" class="btn btn-default btn-sm" data-toggle="tooltip" target="_blank"><i class="fa fa-eye"></i> 查看<span class="hidden-xs">书籍</span></a>
131133
<a v-if="item.role_id < 2" :href="'/book/' + item.identify + '/setting'" title="书籍设置" class="btn btn-default btn-sm" data-toggle="tooltip" target="_blank"><i class="fa fa-cogs"></i> <span class="hidden-xs">书籍</span>设置</a>
132-
<a v-if="item.role_id < 2" title="拷贝的书籍,需要重新发布前台才能阅读" href="javascript:;" class="btn btn-default btn-sm btn-copy-book" :data-index="$index" data-toggle="tooltip" target="_blank"><i class="fa fa-copy"></i> 拷贝<span class="hidden-xs">书籍</span></a>
133-
<a v-if="item.role_id < 2" :href="'/book/'+ item.identify +'/generate'" class="btn btn-default btn-sm ajax-get confirm" :data-identify="item.identify">
134-
<i class="fa fa-book"></i> 生成电子书
135-
</a>
134+
135+
{{if or $.chrome_is_installed $.puppeteer_is_installed}}
136+
<a v-if="item.role_id < 2" title="拷贝的书籍,需要重新发布前台才能阅读" href="javascript:;" class="btn btn-default btn-sm btn-copy-book" :data-index="$index" data-toggle="tooltip" target="_blank"><i class="fa fa-copy"></i> 拷贝<span class="hidden-xs">书籍</span></a>
137+
{{end}}
138+
139+
{{if $.calibre_is_installed}}
140+
<a v-if="item.role_id < 2" :href="'/book/'+ item.identify +'/generate'" class="btn btn-default btn-sm ajax-get confirm" :data-identify="item.identify">
141+
<i class="fa fa-book"></i> 生成电子书
142+
</a>
143+
{{end}}
136144

137145
<template v-if="item.role_id != 3">
138146
<a :href="'/api/' + item.identify + '/edit'" title="编辑文档" data-toggle="tooltip" class="btn btn-default btn-sm"><i class="fa fa-edit" aria-hidden="true"></i> 编辑<span class="hidden-xs">文档</span></a>
139147

140148

141149
<!-- Split button -->
142-
<div class="btn-group">
143-
<button type="button" class="btn btn-default"><i class="fa fa-cloud-upload"></i> 导入书籍</button>
144-
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
145-
<span class="caret"></span>
146-
<span class="sr-only">Toggle Dropdown</span>
147-
</button>
148-
<ul class="dropdown-menu">
149-
<li>
150-
<a href="javascript:void(0);" class="btn-upload-epub" data-toggle="tooltip" :data-identify="item.identify" title="支持epub格式电子书导入。">
151-
<i class="fa fa-cloud-upload"></i> EPUB 上传导入
152-
</a>
153-
</li>
154-
<li>
155-
<a href="javascript:void(0);" class="btn-upload-zip" data-toggle="tooltip" :data-identify="item.identify" title="支持任意zip压缩的markdown书籍导入。">
156-
<i class="fa fa-cloud-upload"></i> ZIP 上传导入
157-
</a>
158-
</li>
159-
<li>
160-
<a href="javascript:void(0);" class="btn-pull-by-zip" data-toggle="tooltip" :data-identify="item.identify" title="从任意源拉取zip压缩的markdown书籍">
161-
<i class="fa fa-link"></i> ZIP 拉取导入
162-
</a>
163-
</li>
164-
<li>
165-
<a href="javascript:void(0);" class="btn-pull-by-git" data-toggle="tooltip" :data-identify="item.identify" title="从Git仓库导入markdown书籍">
166-
<i class="fa fa-git"></i> Git Clone 导入
167-
</a>
168-
</li>
169-
</ul>
170-
</div>
150+
<!-- 安装了chrome或者是puppeteer才可以导入项目 -->
151+
{{if or $.chrome_is_installed $.puppeteer_is_installed}}
152+
<div class="btn-group">
153+
<button type="button" class="btn btn-default"><i class="fa fa-cloud-upload"></i> 导入书籍</button>
154+
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
155+
<span class="caret"></span>
156+
<span class="sr-only">Toggle Dropdown</span>
157+
</button>
158+
<ul class="dropdown-menu">
159+
<li>
160+
<a href="javascript:void(0);" class="btn-upload-epub" data-toggle="tooltip" :data-identify="item.identify" title="支持epub格式电子书导入。">
161+
<i class="fa fa-cloud-upload"></i> EPUB 上传导入
162+
</a>
163+
</li>
164+
<li>
165+
<a href="javascript:void(0);" class="btn-upload-zip" data-toggle="tooltip" :data-identify="item.identify" title="支持任意zip压缩的markdown书籍导入。">
166+
<i class="fa fa-cloud-upload"></i> ZIP 上传导入
167+
</a>
168+
</li>
169+
<li>
170+
<a href="javascript:void(0);" class="btn-pull-by-zip" data-toggle="tooltip" :data-identify="item.identify" title="从任意源拉取zip压缩的markdown书籍">
171+
<i class="fa fa-link"></i> ZIP 拉取导入
172+
</a>
173+
</li>
174+
{{if $.calibre_is_installed}}
175+
<li>
176+
<a href="javascript:void(0);" class="btn-pull-by-git" data-toggle="tooltip" :data-identify="item.identify" title="从Git仓库导入markdown书籍">
177+
<i class="fa fa-git"></i> Git Clone 导入
178+
</a>
179+
</li>
180+
{{end}}
181+
</ul>
182+
</div>
183+
{{end}}
171184
</template>
172185

173186
<div class="btn-group btn-group-download">
@@ -177,9 +190,11 @@
177190
<span class="sr-only">Toggle Dropdown</span>
178191
</button>
179192
<ul class="dropdown-menu">
180-
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=pdf'">导出 PDF</a></li>
181-
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=mobi'">导出 MOBI</a></li>
182-
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=epub'">导出 EPUB</a></li>
193+
{{if $.calibre_is_installed}}
194+
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=pdf'">导出 PDF</a></li>
195+
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=mobi'">导出 MOBI</a></li>
196+
<li><a :href="'{{urlfor "DocumentController.Export" ":key" ""}}' + item.identify+'?output=epub'">导出 EPUB</a></li>
197+
{{end}}
183198
<li><a :href="'{{urlfor "BookController.Export2Markdown"}}?identify=' + item.identify" class="export2markdown">导出 Markdown</a></li>
184199
</ul>
185200
</div>

views/book/setting.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
<div class="m-box">
4141
<div class="box-head">
4242
<strong class="box-title"> 书籍设置</strong>
43-
43+
44+
{{if or $.chrome_is_installed $.puppeteer_is_installed}}
4445
<div class="btn-group pull-right btn-group-sm" style="margin-left: 5px;">
4546
<button type="button" class="btn btn-default"><i class="fa fa-cloud-upload"></i> 导入书籍</button>
4647
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@@ -53,13 +54,16 @@
5354
<i class="fa fa-link"></i> ZIP 拉取导入
5455
</a>
5556
</li>
57+
{{if $.git_is_installed}}
5658
<li>
5759
<a href="javascript:void(0);" class="btn-pull-by-git" data-toggle="tooltip" data-identify="{{.Model.Identify}}" title="从Git仓库导入markdown书籍">
5860
<i class="fa fa-git"></i> Git Clone 导入
5961
</a>
6062
</li>
63+
{{end}}
6164
</ul>
6265
</div>
66+
{{end}}
6367

6468
<a style="margin-left: 5px;" href="/api/{{.Model.Identify}}/edit" class="btn btn-default btn-sm pull-right">编辑文档</a>
6569

@@ -70,9 +74,13 @@
7074
{{else}}
7175
<button type="button" class="btn btn-danger btn-sm pull-right" data-toggle="modal" data-target="#changePrivatelyOwnedModal" style="margin-right: 5px;">转为私有</button>
7276
{{end}}
77+
78+
{{if $.calibre_is_installed}}
7379
<a href="{{urlfor "BookController.Generate" ":key" .Model.Identify}}" style="margin-right: 5px;" class="btn btn-success btn-sm ajax-get pull-right">
7480
生成电子书
7581
</a>
82+
{{end}}
83+
7684
<button type="button" class="btn btn-danger btn-sm pull-right" style="margin-right: 5px;" data-toggle="modal" data-target="#deleteBookModal">删除书籍</button>
7785
{{end}}
7886

views/document/markdown_edit_template.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@
6565
<a href="javascript:;" id="markdown-save" data-toggle="tooltip" data-title="保存内容" class="disabled save"><i class="fa fa-save" aria-hidden="true" name="save"></i></a>
6666
</div>
6767
<div class="editormd-group">
68-
<a href="javascript:;" data-toggle="tooltip" data-title="发布书籍(【普通发布】,适用于正常编写文档且前台排版正常的情况)"><i class="fa fa-paper-plane first" name="release"unselectable="on"></i></a>
68+
<a href="javascript:;" data-toggle="tooltip" data-title="发布书籍"><i class="fa fa-paper-plane first" name="release"unselectable="on"></i></a>
69+
{{if or $.chrome_is_installed $.puppeteer_is_installed}}
6970
<a href="javascript:;" data-toggle="tooltip" data-title="发布书籍(【强制发布】,适用于前台排版错乱的情况)"><i class="fa fa-flash last" name="force-release" unselectable="on"></i></a>
71+
{{end}}
7072
</div>
7173
{{/*<div class="editormd-group">*/}}
7274
{{/*<a href="javascript:;" data-toggle="tooltip" data-title="撤销 (Ctrl-Z)"><i class="fa fa-undo first" name="undo" unselectable="on"></i></a>*/}}
@@ -132,9 +134,11 @@
132134
{{/*<a href="javascript:;" data-toggle="tooltip" data-title="使用帮助"><i class="fa fa-question-circle-o last" aria-hidden="true" name="help"></i></a>*/}}
133135
{{/*</div>*/}}
134136

137+
{{if $.calibre_is_installed}}
135138
<div class="editormd-group pull-right">
136139
<a href="javascript:;" data-toggle="tooltip" data-title="生成电子书"><i class="fa fa-book" name="generate" aria-hidden="true"></i></a>
137140
</div>
141+
{{end}}
138142

139143
<div class="editormd-group">
140144
<a href="javascript:;" data-toggle="tooltip" data-title=""></a>

0 commit comments

Comments
 (0)