Achieve consistency by using a single Image type

This commit is contained in:
2019-06-04 13:37:59 +09:00
parent 3d526f9198
commit dd36c852d3
14 changed files with 21 additions and 20 deletions

View File

@ -0,0 +1,40 @@
package upload
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/utils"
)
// UserCover handles the cover image upload.
func UserCover(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
if !user.IsPro() {
return ctx.Error(http.StatusUnauthorized, "Only available for PRO users")
}
// 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 nil
}