446 Star 3.2K Fork 1.2K

GVP进击的皇虫/BookStack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
attachment_result.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
TruthHun 提交于 2018-02-22 15:19 +08:00 . 假装第一次提交
package models
import (
"strings"
"github.com/TruthHun/BookStack/utils"
"github.com/astaxie/beego/orm"
)
type AttachmentResult struct {
Attachment
IsExist bool
BookName string
DocumentName string
FileShortSize string
Account string
LocalHttpPath string
}
func NewAttachmentResult() *AttachmentResult {
return &AttachmentResult{IsExist: false}
}
func (m *AttachmentResult) Find(id int) (*AttachmentResult, error) {
o := orm.NewOrm()
attach := NewAttachment()
err := o.QueryTable(m.TableNameWithPrefix()).Filter("attachment_id", id).One(attach)
if err != nil {
return m, err
}
m.Attachment = *attach
book := NewBook()
if e := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id", attach.BookId).One(book, "book_name"); e == nil {
m.BookName = book.BookName
} else {
m.BookName = "[不存在]"
}
doc := NewDocument()
if e := o.QueryTable(doc.TableNameWithPrefix()).Filter("document_id", attach.DocumentId).One(doc, "document_name"); e == nil {
m.DocumentName = doc.DocumentName
} else {
m.DocumentName = "[不存在]"
}
if attach.CreateAt > 0 {
member := NewMember()
if e := o.QueryTable(member.TableNameWithPrefix()).Filter("member_id", attach.CreateAt).One(member, "account"); e == nil {
m.Account = member.Account
}
}
m.FileShortSize = utils.FormatBytes(int64(attach.FileSize))
m.LocalHttpPath = strings.Replace(m.FilePath, "\\", "/", -1)
return m, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/truthhun/BookStack.git
git@gitee.com:truthhun/BookStack.git
truthhun
BookStack
BookStack
v1.3.1

搜索帮助