|
|
@@ -25,6 +25,7 @@ import (
|
|
|
"github.com/lifei6671/godoc/models"
|
|
|
"github.com/lifei6671/godoc/utils"
|
|
|
"github.com/lifei6671/godoc/utils/wkhtmltopdf"
|
|
|
+ "github.com/lifei6671/godoc/commands"
|
|
|
)
|
|
|
|
|
|
//DocumentController struct.
|
|
|
@@ -430,7 +431,7 @@ func (c *DocumentController) Upload() {
|
|
|
|
|
|
fileName := "attach_" + strconv.FormatInt(time.Now().UnixNano(), 16)
|
|
|
|
|
|
- filePath := filepath.Join("uploads", time.Now().Format("200601"), fileName+ext)
|
|
|
+ filePath := filepath.Join(commands.WorkingDirectory,"uploads", time.Now().Format("200601"), fileName+ext)
|
|
|
|
|
|
path := filepath.Dir(filePath)
|
|
|
|
|
|
@@ -447,7 +448,7 @@ func (c *DocumentController) Upload() {
|
|
|
attachment.FileName = moreFile.Filename
|
|
|
attachment.CreateAt = c.Member.MemberId
|
|
|
attachment.FileExt = ext
|
|
|
- attachment.FilePath = filePath
|
|
|
+ attachment.FilePath = strings.TrimPrefix(filePath,commands.WorkingDirectory)
|
|
|
attachment.DocumentId = doc_id
|
|
|
|
|
|
if fileInfo, err := os.Stat(filePath); err == nil {
|
|
|
@@ -458,7 +459,11 @@ 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(filePath, "\\", "/", -1)
|
|
|
+
|
|
|
+ attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath,commands.WorkingDirectory), "\\", "/", -1)
|
|
|
+ if strings.HasPrefix(attachment.HttpPath,"//") {
|
|
|
+ attachment.HttpPath = string(attachment.HttpPath[1:])
|
|
|
+ }
|
|
|
is_attach = false
|
|
|
}
|
|
|
|
|
|
@@ -487,19 +492,6 @@ func (c *DocumentController) Upload() {
|
|
|
"is_attach": is_attach,
|
|
|
"attach": attachment,
|
|
|
}
|
|
|
-
|
|
|
- //c.Data["json"] = result
|
|
|
- //c.ServeJSON(true)
|
|
|
- //c.StopRun()
|
|
|
- //
|
|
|
- //returnJSON, err := json.Marshal(result)
|
|
|
- //
|
|
|
- //if err != nil {
|
|
|
- // beego.Error(err)
|
|
|
- //}
|
|
|
- //
|
|
|
- //c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
- //fmt.Fprint(c.Ctx.ResponseWriter,string(returnJSON))
|
|
|
c.Ctx.Output.JSON(result, true, false)
|
|
|
c.StopRun()
|
|
|
}
|
|
|
@@ -554,7 +546,7 @@ func (c *DocumentController) DownloadAttachment() {
|
|
|
if attachment.BookId != book_id {
|
|
|
c.Abort("404")
|
|
|
}
|
|
|
- c.Ctx.Output.Download(attachment.FilePath, attachment.FileName)
|
|
|
+ c.Ctx.Output.Download(strings.Join(commands.WorkingDirectory,attachment.FilePath), attachment.FileName)
|
|
|
|
|
|
c.StopRun()
|
|
|
}
|
|
|
@@ -595,6 +587,8 @@ func (c *DocumentController) RemoveAttachment() {
|
|
|
beego.Error(err)
|
|
|
c.JsonResult(6005, "删除失败")
|
|
|
}
|
|
|
+ os.Remove(strings.Join(commands.WorkingDirectory,attach.FilePath))
|
|
|
+
|
|
|
c.JsonResult(0, "ok", attach)
|
|
|
}
|
|
|
|