diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 0220b6d0f..317baf0b0 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -30,8 +30,8 @@ class StatusController extends Controller $user = Auth::user(); $this->validate($request, [ - 'photo' => 'required|image|max:15000', - 'caption' => 'string|max:150' + 'photo' => 'required|mimes:jpeg,png,bmp,gif|max:' . config('pixelfed.max_photo_size'), + 'caption' => 'string|max:' . config('pixelfed.max_caption_length') ]); $monthHash = hash('sha1', date('Y') . date('m')); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 60c2aec65..8a21a2a7d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -40,7 +40,6 @@ class AppServiceProvider extends ServiceProvider }); Blade::directive('prettySize', function($expression) { - $size = intval($expression); $precision = 0; $short = true; @@ -51,6 +50,11 @@ class AppServiceProvider extends ServiceProvider $res = round($size, $precision).$units[$i]; return ""; }); + + Blade::directive('maxFileSize', function() { + $value = config('pixelfed.max_photo_size'); + return \App\Util\Lexer\PrettyNumber::size($value, true); + }); } /** diff --git a/app/Util/Lexer/PrettyNumber.php b/app/Util/Lexer/PrettyNumber.php index 80227f6fe..23d7ab267 100644 --- a/app/Util/Lexer/PrettyNumber.php +++ b/app/Util/Lexer/PrettyNumber.php @@ -17,4 +17,20 @@ class PrettyNumber { return $expression; } + public static function size($expression, $kb = false) + { + if($kb) { + $expression = $expression * 1024; + } + $size = intval($expression); + $precision = 0; + $short = true; + $units = $short ? + ['B','k','M','G','T','P','E','Z','Y'] : + ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; + for($i = 0; ($size / 1024) > 0.9; $i++, $size /= 1024) {} + $res = round($size, $precision).$units[$i]; + return $res; + } + } \ No newline at end of file diff --git a/config/pixelfed.php b/config/pixelfed.php index 9c33a56cf..9a872e74c 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -76,5 +76,25 @@ return [ 'remote_follow_enabled' => env('REMOTE_FOLLOW', false), 'activitypub_enabled' => env('ACTIVITY_PUB', false), + + /* + |-------------------------------------------------------------------------- + | Photo file size limit + |-------------------------------------------------------------------------- + | + | Update the max photo size, in KB. + | + */ + 'max_photo_size' => env('MAX_PHOTO_SIZE', 15000), + + /* + |-------------------------------------------------------------------------- + | Caption limit + |-------------------------------------------------------------------------- + | + | Change the caption length limit for new local posts. + | + */ + 'max_caption_length' => env('MAX_CAPTION_LENGTH', 150), ]; \ No newline at end of file diff --git a/resources/views/timeline/partial/new-form.blade.php b/resources/views/timeline/partial/new-form.blade.php new file mode 100644 index 000000000..104e4de57 --- /dev/null +++ b/resources/views/timeline/partial/new-form.blade.php @@ -0,0 +1,23 @@ +
+
New Post
+
+
+ @csrf +
+ + + + Max Size: @maxFileSize(). Supported formats: jpeg, png, gif, bmp. + +
+
+ + + + Max length: {{config('pixelfed.max_caption_length')}} characters. + +
+ +
+
+
\ No newline at end of file diff --git a/resources/views/timeline/personal.blade.php b/resources/views/timeline/personal.blade.php index b10490638..ce9415638 100644 --- a/resources/views/timeline/personal.blade.php +++ b/resources/views/timeline/personal.blade.php @@ -17,24 +17,9 @@ @endif -
-
New Post
-
-
- @csrf -
- - -
-
- - -
- -
-
-
+ @include('timeline.partial.new-form') +
@foreach($timeline as $item) diff --git a/resources/views/timeline/public.blade.php b/resources/views/timeline/public.blade.php index 7f5d9afd2..e5b814f1a 100644 --- a/resources/views/timeline/public.blade.php +++ b/resources/views/timeline/public.blade.php @@ -17,23 +17,8 @@
@endif -
-
New Post
-
-
- @csrf -
- - -
-
- - -
- -
-
-
+ + @include('timeline.partial.new-form')
@foreach($timeline as $item)