diff --git a/controllers/document.go b/controllers/document.go index 91421985..b2841c24 100644 --- a/controllers/document.go +++ b/controllers/document.go @@ -21,11 +21,11 @@ import ( "github.com/astaxie/beego/orm" "github.com/boombuler/barcode" "github.com/boombuler/barcode/qr" + "github.com/lifei6671/godoc/commands" "github.com/lifei6671/godoc/conf" "github.com/lifei6671/godoc/models" "github.com/lifei6671/godoc/utils" "github.com/lifei6671/godoc/utils/wkhtmltopdf" - "github.com/lifei6671/godoc/commands" ) //DocumentController struct. @@ -431,7 +431,7 @@ func (c *DocumentController) Upload() { 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) @@ -448,7 +448,7 @@ func (c *DocumentController) Upload() { attachment.FileName = moreFile.Filename attachment.CreateAt = c.Member.MemberId attachment.FileExt = ext - attachment.FilePath = strings.TrimPrefix(filePath,commands.WorkingDirectory) + attachment.FilePath = strings.TrimPrefix(filePath, commands.WorkingDirectory) attachment.DocumentId = doc_id 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") { - attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath,commands.WorkingDirectory), "\\", "/", -1) - if strings.HasPrefix(attachment.HttpPath,"//") { + attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, commands.WorkingDirectory), "\\", "/", -1) + if strings.HasPrefix(attachment.HttpPath, "//") { attachment.HttpPath = string(attachment.HttpPath[1:]) } is_attach = false @@ -546,7 +546,7 @@ func (c *DocumentController) DownloadAttachment() { if attachment.BookId != book_id { 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() } @@ -587,7 +587,7 @@ func (c *DocumentController) RemoveAttachment() { beego.Error(err) c.JsonResult(6005, "删除失败") } - os.Remove(strings.Join(commands.WorkingDirectory,attach.FilePath)) + os.Remove(filepath.Join(commands.WorkingDirectory, attach.FilePath)) c.JsonResult(0, "ok", attach) } diff --git a/models/attachment.go b/models/attachment.go index 102ca953..978eda18 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -4,11 +4,11 @@ package models import ( "time" + "os" + + "github.com/astaxie/beego" "github.com/astaxie/beego/orm" "github.com/lifei6671/godoc/conf" - "os" - "github.com/astaxie/beego" - "strings" ) // Attachment struct . @@ -58,7 +58,7 @@ func (m *Attachment) Update() error { func (m *Attachment) Delete() error { o := orm.NewOrm() - _,err := o.Delete(m) + _, err := o.Delete(m) if err == 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) { 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 }