58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package picture
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"git.umbach.dev/app-idea/rest-api/modules/config"
|
|
"git.umbach.dev/app-idea/rest-api/modules/rabbitmq"
|
|
"git.umbach.dev/app-idea/rest-api/modules/structs"
|
|
"git.umbach.dev/app-idea/rest-api/routers/api/v1/user"
|
|
"github.com/gofiber/fiber/v2"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func Test(c *fiber.Ctx) error {
|
|
log.Infoln("header", string(c.Request().Header.ContentType()))
|
|
|
|
log.Infoln("formValue", c.FormValue("image"))
|
|
|
|
file, err := c.FormFile("image")
|
|
|
|
if err != nil {
|
|
log.Infoln("err1", err)
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
|
|
f, err := file.Open()
|
|
|
|
if err != nil {
|
|
log.Info("err001")
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
if _, err := io.Copy(buf, f); err != nil {
|
|
log.Info("err002")
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
|
|
log.Infoln("bytes", len(buf.Bytes()))
|
|
|
|
user, err := user.GetUserBySessionId(c.Cookies(config.Cfg.Settings.Cookies.SessionId))
|
|
|
|
if err != nil {
|
|
log.Infoln("err004", err)
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
|
|
log.Infoln("userId", user.Id)
|
|
|
|
rabbitmq.PublishPicture(structs.RabbitmqPictureMessage{Picture: buf.Bytes(), UserId: user.Id, Filename: file.Filename})
|
|
|
|
return c.SendStatus(fiber.StatusOK)
|
|
}
|