|
@@ -6,6 +6,10 @@ import (
|
|
"box-cost/log"
|
|
"box-cost/log"
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "io"
|
|
|
|
+ "os"
|
|
|
|
+ "path"
|
|
|
|
+ "strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
@@ -30,6 +34,8 @@ func Signature(r *GinRouter) {
|
|
|
|
|
|
// 删除签名
|
|
// 删除签名
|
|
r.POST("/signature/delete/:id", SignatureDel)
|
|
r.POST("/signature/delete/:id", SignatureDel)
|
|
|
|
+
|
|
|
|
+ r.POST("/signature/upload/image", SignatureUpload)
|
|
}
|
|
}
|
|
|
|
|
|
// 创建签名
|
|
// 创建签名
|
|
@@ -115,3 +121,32 @@ func SignatureDel(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionSignature, signatureId)
|
|
return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionSignature, signatureId)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 本地上传图片
|
|
|
|
+func SignatureUpload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
+ handle, err := c.FormFile("image")
|
|
|
|
+ // 上传图像接口
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ uploadFile, err := handle.Open()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ext := strings.ToLower(path.Ext(handle.Filename))
|
|
|
|
+ if ext != ".jpg" && ext != ".png" {
|
|
|
|
+ return nil, errors.New("只支持jpg/png图片上传")
|
|
|
|
+ }
|
|
|
|
+ // 保存图片
|
|
|
|
+ os.Mkdir("./signature/", 0777)
|
|
|
|
+ saveFile, err := os.OpenFile("./signature/"+handle.Filename, os.O_WRONLY|os.O_CREATE, 0666)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ io.Copy(saveFile, uploadFile)
|
|
|
|
+ defer uploadFile.Close()
|
|
|
|
+ defer saveFile.Close()
|
|
|
|
+
|
|
|
|
+ return "signature/" + handle.Filename, nil
|
|
|
|
+}
|