mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 00:03:16 +00:00
Add supported file types and max caption length to new post form.
Closes #121 and #136
This commit is contained in:
parent
b437b62780
commit
c53e963537
7 changed files with 70 additions and 37 deletions
|
@ -30,8 +30,8 @@ class StatusController extends Controller
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'photo' => 'required|image|max:15000',
|
'photo' => 'required|mimes:jpeg,png,bmp,gif|max:' . config('pixelfed.max_photo_size'),
|
||||||
'caption' => 'string|max:150'
|
'caption' => 'string|max:' . config('pixelfed.max_caption_length')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$monthHash = hash('sha1', date('Y') . date('m'));
|
$monthHash = hash('sha1', date('Y') . date('m'));
|
||||||
|
|
|
@ -40,7 +40,6 @@ class AppServiceProvider extends ServiceProvider
|
||||||
});
|
});
|
||||||
|
|
||||||
Blade::directive('prettySize', function($expression) {
|
Blade::directive('prettySize', function($expression) {
|
||||||
|
|
||||||
$size = intval($expression);
|
$size = intval($expression);
|
||||||
$precision = 0;
|
$precision = 0;
|
||||||
$short = true;
|
$short = true;
|
||||||
|
@ -51,6 +50,11 @@ class AppServiceProvider extends ServiceProvider
|
||||||
$res = round($size, $precision).$units[$i];
|
$res = round($size, $precision).$units[$i];
|
||||||
return "<?php echo '$res'; ?>";
|
return "<?php echo '$res'; ?>";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Blade::directive('maxFileSize', function() {
|
||||||
|
$value = config('pixelfed.max_photo_size');
|
||||||
|
return \App\Util\Lexer\PrettyNumber::size($value, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,4 +17,20 @@ class PrettyNumber {
|
||||||
return $expression;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -77,4 +77,24 @@ return [
|
||||||
|
|
||||||
'activitypub_enabled' => env('ACTIVITY_PUB', 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),
|
||||||
|
|
||||||
];
|
];
|
23
resources/views/timeline/partial/new-form.blade.php
Normal file
23
resources/views/timeline/partial/new-form.blade.php
Normal 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>
|
|
@ -17,23 +17,8 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
<div class="card">
|
|
||||||
<div class="card-header font-weight-bold">New Post</div>
|
@include('timeline.partial.new-form')
|
||||||
<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>
|
|
||||||
|
|
||||||
<div class="timeline-feed my-5" data-timeline="personal">
|
<div class="timeline-feed my-5" data-timeline="personal">
|
||||||
@foreach($timeline as $item)
|
@foreach($timeline as $item)
|
||||||
|
|
|
@ -17,23 +17,8 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
<div class="card">
|
|
||||||
<div class="card-header font-weight-bold">New Post</div>
|
@include('timeline.partial.new-form')
|
||||||
<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>
|
|
||||||
|
|
||||||
<div class="timeline-feed my-5" data-timeline="public">
|
<div class="timeline-feed my-5" data-timeline="public">
|
||||||
@foreach($timeline as $item)
|
@foreach($timeline as $item)
|
||||||
|
|
Loading…
Reference in a new issue