upload.go 1.8 KB
package v1

import (
	"fmt"
	"opp/controllers"
	"opp/protocol"
	"opp/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
		rsp *protocol.FileResponse = &protocol.FileResponse{}
	)
	defer func() {
		this.Resp(msg)
	}()
	var request = &protocol.FileRequest{}
	for i := 1; i <= 9; i++ {
		var tmp *protocol.FileResponse
		key := fmt.Sprintf("%v%v", "image", i)
		if request.Files, err = this.GetFiles(key); err != nil {
			log.Error(key, err)
			err = nil
			break
		}
		if tmp, err = upload.Image(request); err != nil {
			log.Error(err)
			return
		}
		rsp.Paths = append(rsp.Paths, tmp.Paths...)
	}
	msg = protocol.NewReturnResponse(rsp, err)
}

// Voice
// @router /voice [post]
func (this *UploadController) Voice() {
	var (
		msg *protocol.ResponseMessage
		err error
		rsp *protocol.FileResponse = &protocol.FileResponse{}
	)
	defer func() {
		this.Resp(msg)
	}()
	var request = &protocol.FileRequest{}
	for i := 1; i <= 9; i++ {
		var tmp *protocol.FileResponse
		key := fmt.Sprintf("%v%v", "voice", i)
		if request.Files, err = this.GetFiles(key); err != nil {
			log.Error(key, err)
			err = nil
			break
		}
		if tmp, err = upload.Voice(request); err != nil {
			log.Error(err)
			return
		}
		rsp.Paths = append(rsp.Paths, tmp.Paths...)
	}
	msg = protocol.NewReturnResponse(rsp, err)
}

// Video
// @router /video [post]
func (this *UploadController) Video() {
	var (
		msg *protocol.ResponseMessage
		err error
	)
	defer func() {
		this.Resp(msg)
	}()
	for i := 1; i <= 9; i++ {
		var request = &protocol.FileRequest{}
		if request.Files, err = this.GetFiles("file"); err != nil {
			log.Error(err)
			return
		}
		msg = protocol.NewReturnResponse(upload.Video(request))
	}
}