mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-12-19 19:57:09 +08:00
refactor, replace beego.Error with logs.Error
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"time"
|
||||
|
||||
"fmt"
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -360,7 +361,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