You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.0 KiB
83 lines
2.0 KiB
package web
|
|
|
|
import (
|
|
"errors"
|
|
"service-api/global"
|
|
"service-api/model/request"
|
|
"service-api/model/response"
|
|
"service-api/service"
|
|
"service-api/utils/upload"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Summary 获取文件临时地址(可不用)
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags file
|
|
// @Param data query request.GetFileParams true "..."
|
|
// @Success 200 {string} string "{"code": 0, "data": "","msg": "ok"}"
|
|
// @Success 3000 {string} string "{"code": 1, "msg": ""}"
|
|
// @Router /base/file [get]
|
|
func GetFile(c *gin.Context) {
|
|
var (
|
|
err error
|
|
data map[string]interface{}
|
|
url string
|
|
p request.GetFileParams
|
|
)
|
|
err = c.ShouldBindQuery(&p)
|
|
if err != nil {
|
|
response.FailWithMessage("绑定参数错误", c)
|
|
return
|
|
}
|
|
err, url = service.GetFileUrl("nft", p.FileName)
|
|
if err != nil {
|
|
response.FailWithMessage("获取文件失败", c)
|
|
return
|
|
}
|
|
data = make(map[string]interface{})
|
|
data["url"] = url
|
|
response.OkWithData(data, c)
|
|
}
|
|
|
|
// 上传文件
|
|
// @Summary 上传文件
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags file
|
|
// @Accept multipart/form-data
|
|
// @Param file formData string true "file文件"
|
|
// @Success 200 {string} string "{"code": 0, "data": "","msg": "Transaction complete"}"
|
|
// @Success 3000 {string} string "{"code": 1, "msg": ""}"
|
|
// @Router /base/upload [post]
|
|
func UploadFile(c *gin.Context) {
|
|
var (
|
|
err error
|
|
Local = upload.Local{}
|
|
reqParam upload.ParamsUpload
|
|
fileName string
|
|
file upload.FileResponse
|
|
)
|
|
if err = c.ShouldBind(&reqParam); err != nil || reqParam.File == nil {
|
|
//fmt.Println(reqParam.File)
|
|
err = errors.New("参数有误")
|
|
goto RESP
|
|
}
|
|
// if !upload.CheckFileSuffix(reqParam.File.Filename, "graph") {
|
|
// err = errors.New("文件类型不可取")
|
|
// goto RESP
|
|
// }
|
|
fileName, _, err = Local.UploadFile(reqParam.File)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
file.FileUrl = global.MG_CONFIG.Minio.AsseptUrl + fileName
|
|
RESP:
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
} else {
|
|
response.OkWithData(file, c)
|
|
}
|
|
}
|
|
|