diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 0220b6d0..317baf0b 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 60c2aec6..8a21a2a7 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 80227f6f..23d7ab26 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 9c33a56c..9a872e74 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 00000000..104e4de5 --- /dev/null +++ b/resources/views/timeline/partial/new-form.blade.php @@ -0,0 +1,23 @@ +