mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-12-19 19:57:09 +08:00
chore!(all): attempt to update beego to v2
BREAKING CHANGE: beego has update to v2, and this version of mindoc IS NOT TESTED AND STABLE!!!
This commit is contained in:
@@ -12,8 +12,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/beego/beego/v2/adapter"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/cache"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
@@ -142,7 +143,7 @@ func (item *Document) RecursiveDocument(docId int) error {
|
||||
|
||||
_, err := o.Raw("SELECT document_id FROM " + item.TableNameWithPrefix() + " WHERE parent_id=" + strconv.Itoa(docId)).Values(&maps)
|
||||
if err != nil {
|
||||
beego.Error("RecursiveDocument => ", err)
|
||||
logs.Error("RecursiveDocument => ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -164,11 +165,11 @@ func (item *Document) PutToCache() {
|
||||
if m.Identify == "" {
|
||||
|
||||
if err := cache.Put("Document.Id."+strconv.Itoa(m.DocumentId), m, time.Second*3600); err != nil {
|
||||
beego.Info("文档缓存失败:", m.DocumentId)
|
||||
logs.Info("文档缓存失败:", m.DocumentId)
|
||||
}
|
||||
} else {
|
||||
if err := cache.Put(fmt.Sprintf("Document.BookId.%d.Identify.%s", m.BookId, m.Identify), m, time.Second*3600); err != nil {
|
||||
beego.Info("文档缓存失败:", m.DocumentId)
|
||||
logs.Info("文档缓存失败:", m.DocumentId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +191,7 @@ func (item *Document) RemoveCache() {
|
||||
func (item *Document) FromCacheById(id int) (*Document, error) {
|
||||
|
||||
if err := cache.Get("Document.Id."+strconv.Itoa(id), &item); err == nil && item.DocumentId > 0 {
|
||||
beego.Info("从缓存中获取文档信息成功 ->", item.DocumentId)
|
||||
logs.Info("从缓存中获取文档信息成功 ->", item.DocumentId)
|
||||
return item, nil
|
||||
}
|
||||
|
||||
@@ -211,7 +212,7 @@ func (item *Document) FromCacheByIdentify(identify string, bookId int) (*Documen
|
||||
key := fmt.Sprintf("Document.BookId.%d.Identify.%s", bookId, identify)
|
||||
|
||||
if err := cache.Get(key, item); err == nil && item.DocumentId > 0 {
|
||||
beego.Info("从缓存中获取文档信息成功 ->", key)
|
||||
logs.Info("从缓存中获取文档信息成功 ->", key)
|
||||
return item, nil
|
||||
}
|
||||
|
||||
@@ -247,14 +248,14 @@ func (item *Document) ReleaseContent() error {
|
||||
err := item.Processor().InsertOrUpdate("release")
|
||||
|
||||
if err != nil {
|
||||
beego.Error(fmt.Sprintf("发布失败 -> %+v", item), err)
|
||||
logs.Error(fmt.Sprintf("发布失败 -> %+v", item), err)
|
||||
return err
|
||||
}
|
||||
//当文档发布后,需要清除已缓存的转换文档和文档缓存
|
||||
item.RemoveCache()
|
||||
|
||||
if err := os.RemoveAll(filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(item.BookId))); err != nil {
|
||||
beego.Error("删除已缓存的文档目录失败 -> ", filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(item.BookId)))
|
||||
logs.Error("删除已缓存的文档目录失败 -> ", filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(item.BookId)))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -285,7 +286,7 @@ func (item *Document) Processor() *Document {
|
||||
}
|
||||
content.WriteString("</ul></div>")
|
||||
if docQuery == nil {
|
||||
docQuery, err = goquery.NewDocumentFromReader(content);
|
||||
docQuery, err = goquery.NewDocumentFromReader(content)
|
||||
} else {
|
||||
if selector := docQuery.Find("div.wiki-bottom").First(); selector.Size() > 0 {
|
||||
selector.BeforeHtml(content.String())
|
||||
@@ -329,7 +330,7 @@ func (item *Document) Processor() *Document {
|
||||
selector.First().AppendHtml(release)
|
||||
}
|
||||
}
|
||||
cdnimg := beego.AppConfig.String("cdnimg")
|
||||
cdnimg := adapter.AppConfig.String("cdnimg")
|
||||
|
||||
docQuery.Find("img").Each(func(i int, selection *goquery.Selection) {
|
||||
|
||||
@@ -356,7 +357,7 @@ func (item *Document) Processor() *Document {
|
||||
selection.SetAttr("href", "#")
|
||||
return
|
||||
}
|
||||
val = strings.Replace(strings.ToLower(val), " ", "",-1)
|
||||
val = strings.Replace(strings.ToLower(val), " ", "", -1)
|
||||
//移除危险脚本链接
|
||||
if strings.HasPrefix(val, "data:text/html") ||
|
||||
strings.HasPrefix(val, "vbscript:") ||
|
||||
|
||||
Reference in New Issue
Block a user