From 37f9c7c8d658300f0bdc6c57454bb295ea7cce78 Mon Sep 17 00:00:00 2001 From: boojack Date: Sat, 18 Feb 2023 10:48:31 +0800 Subject: [PATCH] chore: update avatar max size (#1109) --- api/user.go | 8 ++++-- store/user.go | 6 ++--- web/src/components/Sidebar.tsx | 30 +++++++++++++++------- web/src/components/UpdateAccountDialog.tsx | 2 -- web/src/components/UserAvatar.tsx | 2 +- web/src/less/siderbar.less | 12 --------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/api/user.go b/api/user.go index b2390a4f..cb1e1ccd 100644 --- a/api/user.go +++ b/api/user.go @@ -56,7 +56,6 @@ type UserCreate struct { Email string `json:"email"` Nickname string `json:"nickname"` Password string `json:"password"` - AvatarURL string `json:"avatarUrl"` PasswordHash string OpenID string } @@ -111,7 +110,12 @@ func (patch UserPatch) Validate() error { if patch.Nickname != nil && len(*patch.Nickname) > 64 { return fmt.Errorf("nickname is too long, maximum length is 64") } - if patch.Email != nil { + if patch.AvatarURL != nil { + if len(*patch.AvatarURL) > 2<<20 { + return fmt.Errorf("avatar is too large, maximum is 2MB") + } + } + if patch.Email != nil && *patch.Email != "" { if len(*patch.Email) > 256 { return fmt.Errorf("email is too long, maximum length is 256") } diff --git a/store/user.go b/store/user.go index 90378295..fdddbe50 100644 --- a/store/user.go +++ b/store/user.go @@ -182,10 +182,9 @@ func createUser(ctx context.Context, tx *sql.Tx, create *api.UserCreate) (*userR email, nickname, password_hash, - open_id, - avatar_url + open_id ) - VALUES (?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?) RETURNING id, username, role, email, nickname, password_hash, open_id, avatar_url, created_ts, updated_ts, row_status ` var userRaw userRaw @@ -196,7 +195,6 @@ func createUser(ctx context.Context, tx *sql.Tx, create *api.UserCreate) (*userR create.Nickname, create.PasswordHash, create.OpenID, - create.AvatarURL, ).Scan( &userRaw.ID, &userRaw.Username, diff --git a/web/src/components/Sidebar.tsx b/web/src/components/Sidebar.tsx index 746531c9..000503ab 100644 --- a/web/src/components/Sidebar.tsx +++ b/web/src/components/Sidebar.tsx @@ -32,20 +32,32 @@ const Sidebar = () => {