Merge pull request #1977 from pixelfed/staging

Update status edit view
This commit is contained in:
daniel 2020-01-29 23:05:59 -07:00 committed by GitHub
commit a7e655d237
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 13 deletions

View file

@ -978,6 +978,9 @@ class ApiV1Controller extends Controller
} }
} }
$filterClass = in_array($request->input('filter_class'), Filter::classes()) ? $request->input('filter_class') : null;
$filterName = in_array($request->input('filter_name'), Filter::names()) ? $request->input('filter_name') : null;
$monthHash = hash('sha1', date('Y').date('m')); $monthHash = hash('sha1', date('Y').date('m'));
$userHash = hash('sha1', $user->id . (string) $user->created_at); $userHash = hash('sha1', $user->id . (string) $user->created_at);
@ -1001,8 +1004,8 @@ class ApiV1Controller extends Controller
$media->size = $photo->getSize(); $media->size = $photo->getSize();
$media->mime = $photo->getMimeType(); $media->mime = $photo->getMimeType();
$media->caption = $request->input('description'); $media->caption = $request->input('description');
$media->filter_class = $request->input('filter_class'); $media->filter_class = $filterClass;
$media->filter_name = $request->input('filter_name'); $media->filter_name = $filterName;
$media->save(); $media->save();
switch ($media->mime) { switch ($media->mime) {

View file

@ -24,6 +24,7 @@ use App\Transformer\Api\{
StatusTransformer StatusTransformer
}; };
use League\Fractal; use League\Fractal;
use App\Util\Media\Filter;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Jobs\AvatarPipeline\AvatarOptimize; use App\Jobs\AvatarPipeline\AvatarOptimize;
@ -231,6 +232,9 @@ class BaseApiController extends Controller
} }
} }
$filterClass = in_array($request->input('filter_class'), Filter::classes()) ? $request->input('filter_class') : null;
$filterName = in_array($request->input('filter_name'), Filter::names()) ? $request->input('filter_name') : null;
$monthHash = hash('sha1', date('Y').date('m')); $monthHash = hash('sha1', date('Y').date('m'));
$userHash = hash('sha1', $user->id . (string) $user->created_at); $userHash = hash('sha1', $user->id . (string) $user->created_at);
@ -253,8 +257,8 @@ class BaseApiController extends Controller
$media->original_sha256 = $hash; $media->original_sha256 = $hash;
$media->size = $photo->getSize(); $media->size = $photo->getSize();
$media->mime = $photo->getMimeType(); $media->mime = $photo->getMimeType();
$media->filter_class = $request->input('filter_class'); $media->filter_class = $filterClass;
$media->filter_name = $request->input('filter_name'); $media->filter_name = $filterName;
$media->save(); $media->save();
$url = URL::temporarySignedRoute( $url = URL::temporarySignedRoute(

View file

@ -229,8 +229,8 @@ class StatusController extends Controller
$user = Auth::user()->profile; $user = Auth::user()->profile;
$status = Status::whereProfileId($user->id) $status = Status::whereProfileId($user->id)
->with(['media']) ->with(['media'])
->where('created_at', '>', now()->subHours(24))
->findOrFail($id); ->findOrFail($id);
return view('status.edit', compact('user', 'status')); return view('status.edit', compact('user', 'status'));
} }
@ -240,6 +240,7 @@ class StatusController extends Controller
$user = Auth::user()->profile; $user = Auth::user()->profile;
$status = Status::whereProfileId($user->id) $status = Status::whereProfileId($user->id)
->with(['media']) ->with(['media'])
->where('created_at', '>', now()->subHours(24))
->findOrFail($id); ->findOrFail($id);
$this->validate($request, [ $this->validate($request, [
@ -254,7 +255,7 @@ class StatusController extends Controller
$media = Media::whereProfileId($user->id) $media = Media::whereProfileId($user->id)
->whereStatusId($status->id) ->whereStatusId($status->id)
->find($id); ->findOrFail($id);
$changed = false; $changed = false;
@ -263,7 +264,7 @@ class StatusController extends Controller
$changed = true; $changed = true;
} }
if ($media->filter_class != $filter) { if ($media->filter_class != $filter && in_array($filter, Filter::classes())) {
$media->filter_class = $filter; $media->filter_class = $filter;
$changed = true; $changed = true;
} }

View file

@ -113,4 +113,14 @@ trait User {
{ {
return 35; return 35;
} }
public function getMaxPostEditsPerHourAttribute()
{
return 10;
}
public function getMaxPostEditsPerDayAttribute()
{
return 20;
}
} }

View file

@ -38,7 +38,7 @@
@csrf @csrf
<input type="hidden" name="media_id" value="{{$media->id}}"> <input type="hidden" name="media_id" value="{{$media->id}}">
<div class="filter-wrapper {{$media->filter_class}}" data-filter="{{$media->filter_class}}"> <div class="filter-wrapper {{$media->filter_class}}" data-filter="{{$media->filter_class}}">
<img class="img-fluid" src="{{$media->thumbnailUrl()}}" width="100%"> <img class="img-fluid" src="{{$media->url()}}" width="100%">
</div> </div>
<div class="p-3"> <div class="p-3">
<div class="form-group"> <div class="form-group">
@ -69,12 +69,9 @@
@endsection @endsection
@push('scripts') @push('scripts')
<script type="text/javascript" src="{{ mix('js/compose.js') }}"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
new Vue({ App.boot();
el: '#content'
});
$('.form-filters').each(function(i,d) { $('.form-filters').each(function(i,d) {
let el = $(d); let el = $(d);
let filter = el.data('filter'); let filter = el.data('filter');

View file

@ -405,7 +405,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('p/{username}/{id}/c', 'CommentController@showAll'); Route::get('p/{username}/{id}/c', 'CommentController@showAll');
Route::get('p/{username}/{id}/embed', 'StatusController@showEmbed'); Route::get('p/{username}/{id}/embed', 'StatusController@showEmbed');
Route::get('p/{username}/{id}/edit', 'StatusController@edit'); Route::get('p/{username}/{id}/edit', 'StatusController@edit');
Route::post('p/{username}/{id}/edit', 'StatusController@editStore'); Route::post('p/{username}/{id}/edit', 'StatusController@editStore')->middleware('throttle:maxPostEditsPerHour,60')->middleware('throttle:maxPostEditsPerDay,1440');
Route::get('p/{username}/{id}.json', 'StatusController@showObject'); Route::get('p/{username}/{id}.json', 'StatusController@showObject');
Route::get('p/{username}/{id}', 'StatusController@show'); Route::get('p/{username}/{id}', 'StatusController@show');
Route::get('{username}/embed', 'ProfileController@embed'); Route::get('{username}/embed', 'ProfileController@embed');