Added cover image upload
This commit is contained in:
@ -190,6 +190,7 @@ func Configure(app *aero.Application) {
|
||||
|
||||
// Upload
|
||||
app.Post("/api/upload/avatar", upload.Avatar)
|
||||
app.Post("/api/upload/cover", upload.Cover)
|
||||
|
||||
// Admin
|
||||
l.Page("/admin", admin.Get)
|
||||
|
@ -39,7 +39,7 @@ component ProfileHeader(viewUser *arn.User, user *arn.User, uri string)
|
||||
|
||||
component ProfileHead(viewUser *arn.User, user *arn.User, uri string)
|
||||
.profile
|
||||
img.profile-cover.lazy(data-src=viewUser.CoverImageURL(), data-webp="true", alt="Cover image")
|
||||
img.profile-cover.lazy(data-src=viewUser.CoverLink("large"), data-webp="true", alt="Cover image")
|
||||
|
||||
.profile-image-container.mountable.never-unmount
|
||||
ProfileImage(viewUser)
|
||||
|
@ -27,7 +27,7 @@ component SettingsPersonal(user *arn.User)
|
||||
|
||||
.widget.mountable(data-api="/api/settings/" + user.ID)
|
||||
h3.widget-title
|
||||
Icon("picture-o")
|
||||
Icon("camera")
|
||||
span Avatar
|
||||
|
||||
//- .widget-section
|
||||
@ -55,16 +55,26 @@ component SettingsPersonal(user *arn.User)
|
||||
//- //- File upload
|
||||
//- if user.Settings().Avatar.Source == "FileSystem"
|
||||
|
||||
InputImage("avatar-input", "File")
|
||||
InputImage("avatar-input", "File", "/api/upload/avatar")
|
||||
|
||||
.profile-image-container.avatar-preview
|
||||
if user.HasAvatar()
|
||||
img#avatar-input-preview.profile-image.mountable(src=user.AvatarLink("large"), alt="Profile image", title="Recommended: 560 x 560 | PNG or JPG")
|
||||
img#avatar-input-preview.profile-image.lazy(data-src=user.AvatarLink("large"), data-webp="true", alt="Profile image", title="Recommended: 560 x 560 | PNG or JPG")
|
||||
else
|
||||
img#avatar-input-preview.profile-image.hidden(src=user.AvatarLink("large"), alt="Profile image", title="Recommended: 560 x 560 | PNG or JPG")
|
||||
|
||||
#avatar-input-preview-svg
|
||||
SVGProfileImage(user)
|
||||
|
||||
.widget.mountable(data-api="/api/settings/" + user.ID)
|
||||
h3.widget-title
|
||||
Icon("picture-o")
|
||||
span Cover
|
||||
|
||||
InputImage("cover-input", "File", "/api/upload/cover")
|
||||
|
||||
.cover-preview
|
||||
img#cover-input-preview.profile-cover.lazy(data-src=user.CoverLink("small"), data-webp="true", alt="Cover image")
|
||||
|
||||
component SettingsNotifications(user *arn.User)
|
||||
SettingsTabs
|
||||
@ -237,13 +247,13 @@ component SettingsAccounts(user *arn.User)
|
||||
|
||||
ImportLists(user)
|
||||
|
||||
.widget.mountable
|
||||
h3.widget-title
|
||||
Icon("upload")
|
||||
span Export
|
||||
//- .widget.mountable
|
||||
//- h3.widget-title
|
||||
//- Icon("upload")
|
||||
//- span Export
|
||||
|
||||
.widget-section
|
||||
label JSON:
|
||||
a.button(href="/api/animelist/" + user.ID)
|
||||
Icon("upload")
|
||||
span Export anime list as JSON
|
||||
//- .widget-section
|
||||
//- label JSON:
|
||||
//- a.button(href="/api/animelist/" + user.ID)
|
||||
//- Icon("upload")
|
||||
//- span Export anime list as JSON
|
@ -16,6 +16,16 @@
|
||||
.avatar-preview
|
||||
margin 0 auto
|
||||
|
||||
.cover-preview
|
||||
width 100%
|
||||
height 0
|
||||
padding-top 25%
|
||||
position relative
|
||||
margin 0 auto
|
||||
|
||||
#cover-input-preview
|
||||
border-radius 3px
|
||||
|
||||
.settings-info-text
|
||||
text-align center
|
||||
font-size 0.9rem
|
||||
|
@ -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
36
pages/upload/cover.go
Normal 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"
|
||||
}
|
Reference in New Issue
Block a user