|
|
@@ -1,9 +1,15 @@ |
|
|
|
package hdl |
|
|
|
|
|
|
|
import ( |
|
|
|
"applet/app/comm/db" |
|
|
|
"applet/app/comm/e" |
|
|
|
md2 "applet/app/comm/md" |
|
|
|
svc2 "applet/app/comm/svc" |
|
|
|
"applet/app/comm/utils" |
|
|
|
"applet/app/comm/utils/logx" |
|
|
|
"applet/app/store/md" |
|
|
|
"applet/app/store/svc" |
|
|
|
"fmt" |
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
) |
|
|
|
|
|
|
@@ -33,3 +39,73 @@ func Sms(c *gin.Context) { |
|
|
|
func ChangePwd(c *gin.Context) { |
|
|
|
svc.ChangePwd(c) |
|
|
|
} |
|
|
|
func ImgReqUpload(c *gin.Context) { |
|
|
|
// 文件名名称 |
|
|
|
var args struct { |
|
|
|
Dir string `json:"dir"` |
|
|
|
FileName string `json:"file_name"` |
|
|
|
FileSize int64 `json:"file_size"` // 文件大小, 单位byte |
|
|
|
} |
|
|
|
if err := c.ShouldBindJSON(&args); err != nil || args.FileSize < 1 || args.FileName == "" { |
|
|
|
logx.Warn(err) |
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS) |
|
|
|
return |
|
|
|
} |
|
|
|
// 限制用户上传目录 |
|
|
|
if _, ok := md2.FileUserDir[args.Dir]; !ok { |
|
|
|
e.OutErr(c, e.ERR_FORBIDEN) |
|
|
|
return |
|
|
|
} |
|
|
|
scheme := "http" |
|
|
|
if c.Request.TLS != nil { |
|
|
|
scheme = "https" |
|
|
|
} |
|
|
|
// 拼装回调地址 |
|
|
|
callbackUrl := scheme + "://" + c.Request.Host + "/api/v1/campTask/store/img/callback?master_id=" + c.GetString("mid") |
|
|
|
utils.FilePutContents("qny", callbackUrl) |
|
|
|
res, err := svc2.ImgReqUpload(c, "", args.Dir, args.FileName, callbackUrl, args.FileSize) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, 400, err) |
|
|
|
return |
|
|
|
} |
|
|
|
my := utils.SerializeStr(res) |
|
|
|
var my1 map[string]interface{} |
|
|
|
utils.Unserialize([]byte(my), &my1) |
|
|
|
e.OutSuc(c, my1, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
func FileImgCallback(c *gin.Context) { |
|
|
|
masterID := c.Query("master_id") |
|
|
|
c.Set("mid", masterID) |
|
|
|
var args md2.FileCallback |
|
|
|
err := c.ShouldBindJSON(&args) |
|
|
|
utils.FilePutContents("qiniuyun", masterID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
utils.FilePutContents("qiniuyun", utils.SerializeStr(err)) |
|
|
|
fmt.Println("七牛云上传回调参数错误:>>>>>>>>>>", err) |
|
|
|
e.OutErr(c, 200, e.ERR_INVALID_ARGS) |
|
|
|
return |
|
|
|
} |
|
|
|
res := map[string]interface{}{ |
|
|
|
"name": args.FileName, |
|
|
|
"fname": getFileNameURL(c, args.FileName), |
|
|
|
"fsize": args.FileSize, |
|
|
|
"provider": args.Provider, |
|
|
|
"uid": args.Uid, |
|
|
|
"dir_id": args.DirId, |
|
|
|
"w": args.Width, |
|
|
|
"h": args.Height, |
|
|
|
} |
|
|
|
e.OutSuc(c, &res, nil) |
|
|
|
} |
|
|
|
|
|
|
|
func getFileNameURL(c *gin.Context, filename string) string { |
|
|
|
protocol := db.SysCfgGet(c, "file_bucket_scheme") |
|
|
|
domain := db.SysCfgGet(c, "file_bucket_host") |
|
|
|
imgformat := db.SysCfgGet(c, "file_avatar_thumbnail") |
|
|
|
if protocol != "" && domain != "" && imgformat != "" { |
|
|
|
return protocol + "://" + domain + "/" + filename |
|
|
|
} |
|
|
|
return filename |
|
|
|
} |