From b85d351bc507e4a775d56b92aa0aabb3cbee2301 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Dec 2018 00:09:36 -0700 Subject: [PATCH] Update avatar logic, allow custom file size limits. Fixes #654 --- .../Controllers/Api/BaseApiController.php | 2 +- app/Http/Controllers/AvatarController.php | 2 +- config/pixelfed.php | 10 +++++++ resources/views/settings/home.blade.php | 28 +++++++++++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index ad717dfe..c87dd198 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -123,7 +123,7 @@ class BaseApiController extends Controller public function avatarUpdate(Request $request) { $this->validate($request, [ - 'upload' => 'required|mimes:jpeg,png,gif|max:2000', + 'upload' => 'required|mimes:jpeg,png,gif|max:'.config('pixelfed.max_avatar_size'), ]); try { diff --git a/app/Http/Controllers/AvatarController.php b/app/Http/Controllers/AvatarController.php index 31824abc..f8a201b8 100644 --- a/app/Http/Controllers/AvatarController.php +++ b/app/Http/Controllers/AvatarController.php @@ -19,7 +19,7 @@ class AvatarController extends Controller public function store(Request $request) { $this->validate($request, [ - 'avatar' => 'required|mimes:jpeg,png|max:2000', + 'avatar' => 'required|mimes:jpeg,png|max:'.config('pixelfed.max_avatar_size'), ]); try { diff --git a/config/pixelfed.php b/config/pixelfed.php index 47023105..a5ad0db2 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -107,6 +107,16 @@ return [ */ 'max_photo_size' => env('MAX_PHOTO_SIZE', 15000), + /* + |-------------------------------------------------------------------------- + | Avatar file size limit + |-------------------------------------------------------------------------- + | + | Update the max avatar size, in KB. + | + */ + 'max_avatar_size' => (int) env('MAX_AVATAR_SIZE', 2000), + /* |-------------------------------------------------------------------------- | Caption limit diff --git a/resources/views/settings/home.blade.php b/resources/views/settings/home.blade.php index b54e9bf2..7a82d9a8 100644 --- a/resources/views/settings/home.blade.php +++ b/resources/views/settings/home.blade.php @@ -10,11 +10,12 @@ @csrf
- +

{{Auth::user()->username}}

-

Change Profile Photo

+

Change Profile Photo

+

Max avatar size:

@@ -60,6 +61,25 @@

+
+

Storage Usage

+
+
+ +
+
+
+
+
+ + {{$storage['percentUsed']}}% used + + + {{$storage['usedPretty']}} / {{$storage['limitPretty']}} + +
+
+

@@ -96,6 +116,8 @@ $('.bio-counter').html(val); }); + $('#maxAvatarSize').text(filesize({{config('pixelfed.max_avatar_size') * 1024}}, {round: 0})); + $(document).on('click', '.change-profile-photo', function(e) { e.preventDefault(); swal({ @@ -103,7 +125,7 @@ content: { element: 'input', attributes: { - placeholder: 'Upload your photo', + placeholder: 'Upload your photo.', type: 'file', name: 'photoUpload', id: 'photoUploadInput'