Skip to content

Commit c2bc3f4

Browse files
committed
增加版本库支持
1 parent ab4027e commit c2bc3f4

File tree

144 files changed

+6516
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+6516
-59
lines changed

commands/command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ func RegisterModel() {
100100
models.NewBookCounter(),
101101
models.NewDownloadCounter(),
102102
models.NewEbook(),
103+
models.NewVersion(),
104+
models.NewVersionItem(),
103105
)
104106
migrate.RegisterMigration()
105107
}

controllers/BookController.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (this *BookController) Index() {
9999
}
100100
}
101101

102-
//收藏书籍
102+
// 收藏书籍
103103
func (this *BookController) Star() {
104104
uid := this.BaseController.Member.MemberId
105105
if uid <= 0 {
@@ -193,6 +193,10 @@ func (this *BookController) Setting() {
193193
this.Data["Maps"] = maps
194194
}
195195

196+
ver := models.NewVersion()
197+
this.Data["Versions"] = ver.All()
198+
this.Data["VersionItem"] = ver.GetVersionItem(book.Identify)
199+
196200
this.Data["Cates"], _ = new(models.Category).GetCates(-1, 1)
197201
this.Data["Model"] = book
198202
this.TplName = "book/setting.html"
@@ -277,6 +281,9 @@ func (this *BookController) SaveBook() {
277281
beego.Error(errSearch.Error())
278282
}
279283
}()
284+
versionId, _ := this.GetInt("version")
285+
versionNO := this.GetString("version_no")
286+
models.NewVersion().InsertOrUpdateVersionItem(versionId, book.Identify, book.BookName, versionNO)
280287
go models.CountCategory()
281288
this.JsonResult(0, "ok", bookResult)
282289
}
@@ -322,7 +329,7 @@ func (this *BookController) parseBookNav() (navs models.BookNavs, navStr string)
322329
return
323330
}
324331

325-
//设置书籍私有状态.
332+
// 设置书籍私有状态.
326333
func (this *BookController) PrivatelyOwned() {
327334

328335
status := this.GetString("status")
@@ -407,7 +414,7 @@ func (this *BookController) Transfer() {
407414
this.JsonResult(0, "ok")
408415
}
409416

410-
//上传书籍封面.
417+
// 上传书籍封面.
411418
func (this *BookController) UploadCover() {
412419

413420
bookResult, err := this.IsPermission()
@@ -853,7 +860,7 @@ func (this *BookController) Generate() {
853860
this.JsonResult(0, "电子书生成任务已交由后台执行,请您耐心等待。")
854861
}
855862

856-
//文档排序.
863+
// 文档排序.
857864
func (this *BookController) SaveSort() {
858865

859866
identify := this.Ctx.Input.Param(":key")
@@ -929,7 +936,7 @@ func (this *BookController) IsPermission() (*models.BookResult, error) {
929936
return book, nil
930937
}
931938

932-
//从github等拉取下载markdown书籍
939+
// 从github等拉取下载markdown书籍
933940
func (this *BookController) DownloadProject() {
934941

935942
//处理步骤
@@ -997,7 +1004,7 @@ func (this *BookController) GitPull() {
9971004
this.JsonResult(0, "提交成功,请耐心等待。")
9981005
}
9991006

1000-
//上传书籍
1007+
// 上传书籍
10011008
func (this *BookController) UploadProject() {
10021009
//处理步骤
10031010
//1、接受上传上来的zip文件,并存放到store/temp目录下
@@ -1032,11 +1039,11 @@ func (this *BookController) UploadProject() {
10321039
this.JsonResult(0, "上传成功")
10331040
}
10341041

1035-
//将zip压缩文件解压并录入数据库
1036-
//@param book_id 书籍id(其实有想不标识了可以不要这个的,但是这里的书籍标识只做目录)
1037-
//@param identify 书籍标识
1038-
//@param zipfile 压缩文件
1039-
//@param originFilename 上传文件的原始文件名
1042+
// 将zip压缩文件解压并录入数据库
1043+
// @param book_id 书籍id(其实有想不标识了可以不要这个的,但是这里的书籍标识只做目录)
1044+
// @param identify 书籍标识
1045+
// @param zipfile 压缩文件
1046+
// @param originFilename 上传文件的原始文件名
10401047
func (this *BookController) unzipToData(bookId int, identify, zipFile, originFilename string) {
10411048

10421049
//说明:
@@ -1217,7 +1224,7 @@ func (this *BookController) loadByFolder(bookId int, identify, folder string) {
12171224
}
12181225
}
12191226

1220-
//获取书籍的根目录
1227+
// 获取书籍的根目录
12211228
func (this *BookController) getProjectRoot(fl []filetil.FileList) (root string) {
12221229
var strs []string
12231230
for _, f := range fl {
@@ -1228,7 +1235,7 @@ func (this *BookController) getProjectRoot(fl []filetil.FileList) (root string)
12281235
return utils.LongestCommonPrefix(strs)
12291236
}
12301237

1231-
//查找并替换markdown文件中的路径,把图片链接替换成url的相对路径,把文档间的链接替换成【$+文档标识链接】
1238+
// 查找并替换markdown文件中的路径,把图片链接替换成url的相对路径,把文档间的链接替换成【$+文档标识链接】
12321239
func (this *BookController) fixFileLinks(projectRoot string, identify string) {
12331240
imgBaseUrl := "/uploads/projects/" + identify
12341241
switch utils.StoreType {
@@ -1311,7 +1318,7 @@ func (this *BookController) fixFileLinks(projectRoot string, identify string) {
13111318
}
13121319
}
13131320

1314-
//给书籍打分
1321+
// 给书籍打分
13151322
func (this *BookController) Score() {
13161323
bookId, _ := this.GetInt(":id")
13171324
if bookId == 0 {
@@ -1328,7 +1335,7 @@ func (this *BookController) Score() {
13281335
this.JsonResult(1, "给文档打分失败,请先登录再操作")
13291336
}
13301337

1331-
//添加评论
1338+
// 添加评论
13321339
func (this *BookController) Comment() {
13331340
if this.Member.MemberId == 0 {
13341341
this.JsonResult(1, "请先登录在评论")

controllers/DocumentController.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (this *DocumentController) Index() {
208208
"description": bookResult.Description,
209209
})
210210
this.Data["RelateBooks"] = models.NewRelateBook().Lists(bookResult.BookId)
211+
this.Data["Versions"] = models.NewVersion().GetPublicVersionItems(bookResult.Identify)
211212
}
212213

213214
// 文档首页.
@@ -491,6 +492,33 @@ func (this *DocumentController) Read() {
491492
this.Data["Comments"] = comments
492493
this.Data["IsAllowRead"] = isAllowRead
493494
this.Data["Percent"] = percent
495+
this.Data["Versions"] = models.NewVersion().GetPublicVersionItems(bookResult.Identify)
496+
}
497+
498+
func (this *DocumentController) ReadBook() {
499+
identify := this.Ctx.Input.Param(":key")
500+
if identify == "" {
501+
this.Abort("404")
502+
return
503+
}
504+
505+
book, err := models.NewBook().FindByIdentify(identify, "book_id")
506+
if err != nil || book.BookId == 0 {
507+
this.Abort("404")
508+
return
509+
}
510+
511+
doc, err := models.NewDocument().FirstChapter(book.BookId, "document_id", "identify")
512+
if err != nil || doc.DocumentId == 0 {
513+
this.Abort("404")
514+
return
515+
}
516+
517+
if sign := this.GetString("sign"); sign != "" {
518+
this.SetSession(book.BookId, sign)
519+
}
520+
521+
this.Redirect(beego.URLFor("DocumentController.Read", ":key", identify, ":id", doc.Identify), 302)
494522
}
495523

496524
// 编辑文档.

0 commit comments

Comments
 (0)