Added cover image upload

This commit is contained in:
2018-03-07 14:00:14 +01:00
parent 22f3a767a8
commit d583d9d6f9
9 changed files with 94 additions and 28 deletions

View File

@ -7,7 +7,7 @@ import (
"github.com/animenotifier/notify.moe/utils"
)
// Avatar ...
// Avatar handles the avatar upload.
func Avatar(ctx *aero.Context) string {
user := utils.GetUser(ctx)

36
pages/upload/cover.go Normal file
View File

@ -0,0 +1,36 @@
package upload
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/utils"
)
// Cover handles the cover image upload.
func Cover(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
}
// Retrieve file from post body
data, err := ctx.Request().Body().Bytes()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Reading request body failed", err)
}
// Set cover image file
err = user.SetCoverBytes(data)
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Invalid image format", err)
}
// Save cover image information
user.Save()
return "ok"
}