2018-03-07 13:00:14 +00:00
|
|
|
package upload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Cover handles the cover image upload.
|
2019-06-01 04:55:49 +00:00
|
|
|
func Cover(ctx aero.Context) error {
|
2018-03-07 13:00:14 +00:00
|
|
|
user := utils.GetUser(ctx)
|
|
|
|
|
|
|
|
if user == nil {
|
2018-07-07 03:42:00 +00:00
|
|
|
return ctx.Error(http.StatusUnauthorized, "Not logged in")
|
2018-03-07 13:00:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 13:52:56 +00:00
|
|
|
if !user.IsPro() {
|
2018-07-07 03:42:00 +00:00
|
|
|
return ctx.Error(http.StatusUnauthorized, "Only available for PRO users")
|
2018-03-07 13:52:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 13:00:14 +00:00
|
|
|
// 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()
|
|
|
|
|
2019-06-01 04:55:49 +00:00
|
|
|
return nil
|
2018-03-07 13:00:14 +00:00
|
|
|
}
|