1
0

More avatar providers (#622)

Don't fail if the last avatar file does not exist when deleting it

Fix lint

Remove old global avatar setting and update docs

Generate docs

Invalidate the avatar cache when uploading a new one

Add debug logs

Add caching for upload avatars

Add cache locks

Fix encoding

Resize the uploaded image to a max of 1024 pixels

Remove the old uploaded avatar if one already exists

Add mimetype check for images

Set avatar provider to upload when uploading an avatar

Add upload avatar provider

Make font size smaller to let the initials still look good in smaller sizes

Add debug log

Add cache and resizing of initials avatars

Make font size depend on avatar size

Add drawing initials avatar

Add initials provider

Make the initials avatar provider the default

Add routes

Add user avatar settings handler methods

Add user avatar provider field

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/622
This commit is contained in:
konrad
2020-08-02 17:16:58 +00:00
parent c9117dd037
commit dfb7730b63
24 changed files with 1287 additions and 33 deletions

View File

@ -25,9 +25,12 @@ import (
v1 "code.vikunja.io/api/pkg/routes/api/v1"
"code.vikunja.io/web"
"code.vikunja.io/web/handler"
"github.com/gabriel-vasile/mimetype"
"github.com/labstack/echo/v4"
"io"
"net/http"
"strconv"
"strings"
)
// BackgroundProvider represents a thing which holds a background provider
@ -132,7 +135,18 @@ func (bp *BackgroundProvider) UploadBackground(c echo.Context) error {
}
defer src.Close()
f, err := files.Create(src, file.Filename, uint64(file.Size), auth)
// Validate we're dealing with an image
mime, err := mimetype.DetectReader(src)
if err != nil {
return handler.HandleHTTPError(err, c)
}
if !strings.HasPrefix(mime.String(), "image") {
return c.JSON(http.StatusBadRequest, models.Message{Message: "Uploaded file is no image."})
}
_, _ = src.Seek(0, io.SeekStart)
// Save the file
f, err := files.CreateWithMime(src, file.Filename, uint64(file.Size), auth, mime.String())
if err != nil {
if files.IsErrFileIsTooLarge(err) {
return echo.ErrBadRequest