修复BUG

pull/51/merge
Minho 2017-06-05 13:41:47 +08:00
parent 8a4eabd158
commit 95c63fb1fb
2 changed files with 12 additions and 12 deletions

View File

@ -21,11 +21,11 @@ import (
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/boombuler/barcode" "github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr" "github.com/boombuler/barcode/qr"
"github.com/lifei6671/godoc/commands"
"github.com/lifei6671/godoc/conf" "github.com/lifei6671/godoc/conf"
"github.com/lifei6671/godoc/models" "github.com/lifei6671/godoc/models"
"github.com/lifei6671/godoc/utils" "github.com/lifei6671/godoc/utils"
"github.com/lifei6671/godoc/utils/wkhtmltopdf" "github.com/lifei6671/godoc/utils/wkhtmltopdf"
"github.com/lifei6671/godoc/commands"
) )
//DocumentController struct. //DocumentController struct.
@ -431,7 +431,7 @@ func (c *DocumentController) Upload() {
fileName := "attach_" + strconv.FormatInt(time.Now().UnixNano(), 16) fileName := "attach_" + strconv.FormatInt(time.Now().UnixNano(), 16)
filePath := filepath.Join(commands.WorkingDirectory,"uploads", time.Now().Format("200601"), fileName+ext) filePath := filepath.Join(commands.WorkingDirectory, "uploads", time.Now().Format("200601"), fileName+ext)
path := filepath.Dir(filePath) path := filepath.Dir(filePath)
@ -448,7 +448,7 @@ func (c *DocumentController) Upload() {
attachment.FileName = moreFile.Filename attachment.FileName = moreFile.Filename
attachment.CreateAt = c.Member.MemberId attachment.CreateAt = c.Member.MemberId
attachment.FileExt = ext attachment.FileExt = ext
attachment.FilePath = strings.TrimPrefix(filePath,commands.WorkingDirectory) attachment.FilePath = strings.TrimPrefix(filePath, commands.WorkingDirectory)
attachment.DocumentId = doc_id attachment.DocumentId = doc_id
if fileInfo, err := os.Stat(filePath); err == nil { if fileInfo, err := os.Stat(filePath); err == nil {
@ -460,8 +460,8 @@ func (c *DocumentController) Upload() {
if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, "png") || strings.EqualFold(ext, "gif") { if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, "png") || strings.EqualFold(ext, "gif") {
attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath,commands.WorkingDirectory), "\\", "/", -1) attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, commands.WorkingDirectory), "\\", "/", -1)
if strings.HasPrefix(attachment.HttpPath,"//") { if strings.HasPrefix(attachment.HttpPath, "//") {
attachment.HttpPath = string(attachment.HttpPath[1:]) attachment.HttpPath = string(attachment.HttpPath[1:])
} }
is_attach = false is_attach = false
@ -546,7 +546,7 @@ func (c *DocumentController) DownloadAttachment() {
if attachment.BookId != book_id { if attachment.BookId != book_id {
c.Abort("404") c.Abort("404")
} }
c.Ctx.Output.Download(strings.Join(commands.WorkingDirectory,attachment.FilePath), attachment.FileName) c.Ctx.Output.Download(filepath.Join(commands.WorkingDirectory, attachment.FilePath), attachment.FileName)
c.StopRun() c.StopRun()
} }
@ -587,7 +587,7 @@ func (c *DocumentController) RemoveAttachment() {
beego.Error(err) beego.Error(err)
c.JsonResult(6005, "删除失败") c.JsonResult(6005, "删除失败")
} }
os.Remove(strings.Join(commands.WorkingDirectory,attach.FilePath)) os.Remove(filepath.Join(commands.WorkingDirectory, attach.FilePath))
c.JsonResult(0, "ok", attach) c.JsonResult(0, "ok", attach)
} }

View File

@ -4,11 +4,11 @@ package models
import ( import (
"time" "time"
"os"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/lifei6671/godoc/conf" "github.com/lifei6671/godoc/conf"
"os"
"github.com/astaxie/beego"
"strings"
) )
// Attachment struct . // Attachment struct .
@ -58,7 +58,7 @@ func (m *Attachment) Update() error {
func (m *Attachment) Delete() error { func (m *Attachment) Delete() error {
o := orm.NewOrm() o := orm.NewOrm()
_,err := o.Delete(m) _, err := o.Delete(m)
if err == nil { if err == nil {
if err1 := os.Remove(m.FilePath); err1 != nil { if err1 := os.Remove(m.FilePath); err1 != nil {
@ -83,6 +83,6 @@ func (m *Attachment) Find(id int) (*Attachment, error) {
func (m *Attachment) FindListByDocumentId(doc_id int) (attaches []*Attachment, err error) { func (m *Attachment) FindListByDocumentId(doc_id int) (attaches []*Attachment, err error) {
o := orm.NewOrm() o := orm.NewOrm()
_,err = o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",doc_id).OrderBy("-attachment_id").All(&attaches) _, err = o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc_id).OrderBy("-attachment_id").All(&attaches)
return return
} }