38 lines
768 B
Go
Raw Normal View History

2018-03-02 20:42:34 +00:00
package upload
import (
"bytes"
"fmt"
"image"
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/utils"
)
// Avatar ...
func Avatar(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
}
data, err := ctx.Request().Body().Bytes()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Reading request body failed", err)
}
2018-03-02 21:30:39 +00:00
// Decode
img, format, err := image.Decode(bytes.NewReader(data))
2018-03-02 20:42:34 +00:00
if err != nil {
2018-03-02 21:30:39 +00:00
return ctx.Error(http.StatusBadRequest, "Invalid image format", err)
2018-03-02 20:42:34 +00:00
}
2018-03-02 21:30:39 +00:00
fmt.Println("Avatar received!", len(data), format, img.Bounds().Dx(), img.Bounds().Dy(), user.Nick)
2018-03-02 20:42:34 +00:00
// ioutil.WriteFile("avatar")
return "ok"
}