作者 yangfu

Merge remote-tracking branch 'origin/test'

... ... @@ -138,14 +138,14 @@ func FilterComm(ctx *context.Context) {
//if !CheckSign(ctx) {
// return
//}
//3.查重uuid
if !CheckUuid(ctx) {
return
}
//2.检查token是否有效
if !CheckToken(ctx) {
return
}
//3.查重uuid
//if !CheckUuid(ctx) {
// return
//}
return
}
... ... @@ -223,14 +223,13 @@ func CheckUuid(ctx *context.Context) (result bool) {
)
result = true
defer func() {
if msg != nil {
result = false
if msg.Errno != 0 {
ctx.Output.JSON(msg, false, false)
}
}()
uuid := ctx.Input.Header("x-mmm-uuid")
msg = protocol.NewReturnResponse(auth.CheckUuid(&protocol.CheckUuidRequest{Uuid: uuid}))
if msg != nil {
if msg.Errno != 0 {
log.Error(fmt.Sprintf("%v req:%v resp:%v", ctx.Request.RequestURI, uuid, common.AssertJson(msg)))
}
return
... ...
package v1
import (
"fmt"
"github.com/astaxie/beego"
"opp/controllers"
"opp/internal/utils"
"opp/protocol"
"path/filepath"
"strings"
)
type FileController struct {
controllers.BaseController
}
// DownLoad
// @router /opp/file [post]
func (this *FileController) DownLoad() {
var (
msg *protocol.ResponseMessage
err error
rsp *protocol.FileResponse = &protocol.FileResponse{}
)
defer func() {
if msg.Errno != 0 {
this.Resp(msg)
}
}()
fileUrl := this.Ctx.Request.RequestURI
filePath := strings.Replace(fileUrl, "/file/opp", "", 1)
filePath = filepath.Join(beego.AppConfig.String("source_path"), filePath)
if utils.Exists(filePath) {
this.Ctx.Output.Download(filePath)
} else {
err = protocol.NewCustomMessage(0, fmt.Sprintf("文件不存在:%v", filePath))
}
msg = protocol.NewReturnResponse(rsp, err)
}
... ...
package utils
import "os"
// 判断所给路径文件/文件夹是否存在
func Exists(path string) bool {
_, err := os.Stat(path) //os.Stat获取文件信息
if err != nil {
if os.IsExist(err) {
return true
}
return false
}
return true
}
// 判断所给路径是否为文件夹
func IsDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.IsDir()
}
// 判断所给路径是否为文件
func IsFile(path string) bool {
return !IsDir(path)
}
... ...
... ... @@ -35,7 +35,7 @@ func init() {
log.Info(fmt.Sprintf("init redis:%v", redisSource))
if err != nil {
log.Fatal("connect to redis error address:", beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), err)
//panic(err)
panic(err)
}
dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai&charset=utf8mb4",
beego.AppConfig.String("mysql_user"),
... ...
... ... @@ -287,6 +287,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"],
beego.ControllerComments{
Method: "DownLoad",
Router: `/opp/file`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "AnnouncementRead",
... ...
... ... @@ -33,7 +33,9 @@ func init() {
nsH5 := beego.NewNamespace("h5", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&controllers.H5Controller{}))
beego.AddNamespace(nsH5)
//post 下载文件
beego.Router("/file/opp/*", &v1.FileController{}, "post:DownLoad")
//get 直接获取文件
beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access"))
beego.Handler("/metrics", promhttp.Handler())
... ...
... ... @@ -284,18 +284,21 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
//检查uuid 是否重复
func CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) {
//var (
// logUuid *models.LogUuid
//)
//if len(request.Uuid) == 0 {
// err = common.NewErrorWithMsg(4142, "uuid not empty")
//}
//logUuid, err = models.GetLogUuidByUuid(request.Uuid)
//if err == nil && logUuid != nil {
// err = common.NewErrorWithMsg(4142, "uuid not valid")
//}
//models.AddLogUuid(&models.LogUuid{Uuid: request.Uuid})
//rsp = &protocol.CheckUuidResponse{}
var ()
rsp = &protocol.CheckUuidResponse{}
if len(request.Uuid) == 0 || (request.Uuid == "123456" && beego.BConfig.RunMode != "prod") {
return
}
if redis.Hexists(protocol.RedisKey(protocol.HashUuid), request.Uuid) {
err = protocol.NewErrWithMessage(4142)
log.Error("[CheckUuid] 存在:", request.Uuid, err)
return
}
if e := redis.Hset(protocol.RedisKey(protocol.HashUuid), request.Uuid, request.Uuid, 3600); e != nil {
err = protocol.NewErrWithMessage(4142)
log.Error("[CheckUuid] 设置:", request.Uuid, e)
return
}
return
}
... ...
... ... @@ -55,6 +55,9 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent
var tmpTotal int
models.GetBulletinUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &tmpTotal)
item.MsgTotal = tmpTotal
if tmpTotal == 0 {
continue
}
}
list = append(list, item)
}
... ...
... ... @@ -67,7 +67,7 @@ func UploadFile(request *protocol.FileRequest) (rsp *protocol.FileResponse, err
return
}
}
virtualPath = beego.AppConfig.String("source_host") + filepath.Join(virtualPath, request.FileType, date)
virtualPath = fmt.Sprintf("%v%v/%v/%v", beego.AppConfig.String("source_host"), virtualPath, request.FileType, date)
for i := range request.Files {
f := request.Files[i]
prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32))
... ...