upload.go 1.3 KB
package v1

import (
	"ability/controllers"
	"ability/protocol"
	"ability/services/upload"

	"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
)

type UploadController struct {
	controllers.BaseController
}

// Image
// @router /image [post]
func (this *UploadController) Image() {
	var (
		msg *protocol.ResponseMessage
		err error
	)
	defer func() {
		this.Resp(msg)
	}()
	var request = &protocol.FileRequest{}
	//if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
	//	log.Error(err)
	//	msg = protocol.ReturnResponse(1)
	//	return
	//}
	//if b,m :=this.Valid(request);!b{
	//	msg = m
	//	return
	//}
	if request.Files, err = this.GetFiles("file"); err != nil {
		log.Error(err)
		return
	}
	msg = protocol.NewReturnResponse(upload.Image(request))
}

// Image
// @router /voice [post]
func (this *UploadController) Voice() {
	var (
		msg *protocol.ResponseMessage
		err error
	)
	defer func() {
		this.Resp(msg)
	}()
	var request = &protocol.FileRequest{}
	//if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
	//	log.Error(err)
	//	msg = protocol.ReturnResponse(1)
	//	return
	//}
	//if b,m :=this.Valid(request);!b{
	//	msg = m
	//	return
	//}
	if request.Files, err = this.GetFiles("file"); err != nil {
		log.Error(err)
		return
	}
	msg = protocol.NewReturnResponse(upload.Voice(request))
}