Add supported file types and max caption length to new post form.

Closes #121 and #136
This commit is contained in:
Daniel Supernault 2018-06-02 16:53:35 -06:00
parent b437b62780
commit c53e963537
7 changed files with 70 additions and 37 deletions

View file

@ -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'));

View file

@ -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 "<?php echo '$res'; ?>";
});
Blade::directive('maxFileSize', function() {
$value = config('pixelfed.max_photo_size');
return \App\Util\Lexer\PrettyNumber::size($value, true);
});
}
/**

View file

@ -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;
}
}

View file

@ -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),
];

View file

@ -0,0 +1,23 @@
<div class="card">
<div class="card-header font-weight-bold">New Post</div>
<div class="card-body" id="statusForm">
<form method="post" action="/timeline" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label class="font-weight-bold text-muted small">Upload Image</label>
<input type="file" class="form-control-file" name="photo" accept="image/*">
<small class="form-text text-muted">
Max Size: @maxFileSize(). Supported formats: jpeg, png, gif, bmp.
</small>
</div>
<div class="form-group">
<label class="font-weight-bold text-muted small">Caption</label>
<input type="text" class="form-control" name="caption" placeholder="Add a caption here">
<small class="form-text text-muted">
Max length: {{config('pixelfed.max_caption_length')}} characters.
</small>
</div>
<button type="submit" class="btn btn-outline-primary btn-block">Post</button>
</form>
</div>
</div>

View file

@ -17,24 +17,9 @@
</ul>
</div>
@endif
<div class="card">
<div class="card-header font-weight-bold">New Post</div>
<div class="card-body" id="statusForm">
<form method="post" action="/timeline" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label class="font-weight-bold text-muted small">Upload Image</label>
<input type="file" class="form-control-file" name="photo" accept="image/*">
</div>
<div class="form-group">
<label class="font-weight-bold text-muted small">Caption</label>
<input type="text" class="form-control" name="caption" placeholder="Add a caption here">
</div>
<button type="submit" class="btn btn-outline-primary btn-block">Post</button>
</form>
</div>
</div>
@include('timeline.partial.new-form')
<div class="timeline-feed my-5" data-timeline="personal">
@foreach($timeline as $item)

View file

@ -17,23 +17,8 @@
</ul>
</div>
@endif
<div class="card">
<div class="card-header font-weight-bold">New Post</div>
<div class="card-body" id="statusForm">
<form method="post" action="/timeline" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label class="font-weight-bold text-muted small">Upload Image</label>
<input type="file" class="form-control-file" name="photo" accept="image/*">
</div>
<div class="form-group">
<label class="font-weight-bold text-muted small">Caption</label>
<input type="text" class="form-control" name="caption" placeholder="Add a caption here">
</div>
<button type="submit" class="btn btn-outline-primary btn-block">Post</button>
</form>
</div>
</div>
@include('timeline.partial.new-form')
<div class="timeline-feed my-5" data-timeline="public">
@foreach($timeline as $item)