|
@@ -12,6 +12,9 @@ import (
|
|
|
"os"
|
|
"os"
|
|
|
"path"
|
|
"path"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
+ "strings"
|
|
|
|
|
+ "mime"
|
|
|
|
|
+ "strconv"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// _Upload
|
|
// _Upload
|
|
@@ -37,6 +40,24 @@ func SysAttachment_Upload(c *entitys.CtrlContext) {
|
|
|
// @Failure 403 :id is empty
|
|
// @Failure 403 :id is empty
|
|
|
func SysAttachment_Download(c *entitys.CtrlContext) {
|
|
func SysAttachment_Download(c *entitys.CtrlContext) {
|
|
|
attrId := c.Ctx.Query("id")
|
|
attrId := c.Ctx.Query("id")
|
|
|
|
|
+ //gt := c.Ctx.Query("get_thumb")
|
|
|
|
|
+ var engine = c.PlatformDbEngine
|
|
|
|
|
+ var attach = sysmodel.SysAttachment{Id:attrId}
|
|
|
|
|
+ has, err := engine.Get(&attach)
|
|
|
|
|
+ if err != nil || !has {
|
|
|
|
|
+ syslogs.Error("获取附件出错了:", err)
|
|
|
|
|
+ c.Ctx.JSON(500, sysmodel.SysReturn{500, "获取附件出错了", nil})
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ filePath := "files/"+ attach.Id
|
|
|
|
|
+
|
|
|
|
|
+ c.Ctx.Header("Content-Disposition", "attachment;filename=\""+sysutils.FormatForBrowse(c.Ctx.Request.UserAgent(), attach.Name)+"\"")
|
|
|
|
|
+ c.Ctx.Header("Content-Type", strings.Replace(mime.TypeByExtension(attach.Ext), "charset=utf-8", "", -1))
|
|
|
|
|
+ c.Ctx.Header("Content-Length", strconv.FormatInt(int64(attach.Size), 10))
|
|
|
|
|
+ c.Ctx.File(filePath)
|
|
|
|
|
+ c.Ctx.Writer.WriteHeader(200)
|
|
|
|
|
+ /*attrId := c.Ctx.Query("id")
|
|
|
|
|
|
|
|
filePath := fmt.Sprintf("files/%s", attrId)
|
|
filePath := fmt.Sprintf("files/%s", attrId)
|
|
|
|
|
|
|
@@ -48,8 +69,7 @@ func SysAttachment_Download(c *entitys.CtrlContext) {
|
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- c.Ctx.Writer.Write(file)
|
|
|
|
|
|
|
+ c.Ctx.Writer.Write(file)*/
|
|
|
|
|
|
|
|
////gt := c.Ctx.Query("get_thumb")
|
|
////gt := c.Ctx.Query("get_thumb")
|
|
|
//var attach sysmodel.SysAttachment
|
|
//var attach sysmodel.SysAttachment
|
|
@@ -130,7 +150,7 @@ func SysAttachment_Delete(c *entitys.CtrlContext) {
|
|
|
attrId := c.Ctx.Query("id")
|
|
attrId := c.Ctx.Query("id")
|
|
|
attach := &sysmodel.SysAttachment{}
|
|
attach := &sysmodel.SysAttachment{}
|
|
|
attach.Id = attrId
|
|
attach.Id = attrId
|
|
|
- _, err := c.Db.Id(attrId).Delete(attach)
|
|
|
|
|
|
|
+ _, err := c.PlatformDbEngine.Id(attrId).Delete(attach)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
syslogs.Error("删除附件出错了:", err)
|
|
syslogs.Error("删除附件出错了:", err)
|
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
|
|
@@ -140,6 +160,27 @@ func SysAttachment_Delete(c *entitys.CtrlContext) {
|
|
|
c.Ctx.JSON(200, sysmodel.SysReturn{200, "", attrId})
|
|
c.Ctx.JSON(200, sysmodel.SysReturn{200, "", attrId})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// _Get
|
|
|
|
|
+// @Title _Get
|
|
|
|
|
+// @Description 获取附件信息
|
|
|
|
|
+// @Param id string false "附件id"
|
|
|
|
|
+// @Success 200 {object} Account
|
|
|
|
|
+// @Failure 403 :id is empty
|
|
|
|
|
+func SysAttachment_Get(c *entitys.CtrlContext) {
|
|
|
|
|
+ var id = c.Ctx.Query("id")
|
|
|
|
|
+ attach := sysmodel.SysAttachment{Id:id}
|
|
|
|
|
+ has, err := c.PlatformDbEngine.Get(&attach)
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ if has {
|
|
|
|
|
+ c.Ctx.JSON(200, sysmodel.SysReturn{200, "", attach})
|
|
|
|
|
+ } else {
|
|
|
|
|
+ c.Ctx.JSON(200, sysmodel.SysReturn{500, "附件不存在", nil})
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ c.Ctx.JSON(200, sysmodel.SysReturn{500, err.Error(), nil})
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func doUpload(c *entitys.CtrlContext) (*sysmodel.SysAttachment, error) {
|
|
func doUpload(c *entitys.CtrlContext) (*sysmodel.SysAttachment, error) {
|
|
|
file, fInfo, err := c.Ctx.Request.FormFile("file")
|
|
file, fInfo, err := c.Ctx.Request.FormFile("file")
|
|
|
if err != nil {
|
|
if err != nil {
|