Update config() to config_cache()

This commit is contained in:
Daniel Supernault 2021-05-11 20:14:51 -06:00
parent 3a9203e039
commit 7895097fc1
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
6 changed files with 149 additions and 149 deletions

View File

@ -1059,7 +1059,7 @@ class ApiV1Controller extends Controller
$profile = $user->profile; $profile = $user->profile;
if(config('pixelfed.enforce_account_limit') == true) { if(config_cache('pixelfed.enforce_account_limit') == true) {
$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) { $size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
return Media::whereUserId($user->id)->sum('size') / 1000; return Media::whereUserId($user->id)->sum('size') / 1000;
}); });

View File

@ -92,7 +92,7 @@ class ComposeController extends Controller
abort_if($limitReached == true, 429); abort_if($limitReached == true, 429);
if(config('pixelfed.enforce_account_limit') == true) { if(config_cache('pixelfed.enforce_account_limit') == true) {
$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) { $size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
return Media::whereUserId($user->id)->sum('size') / 1000; return Media::whereUserId($user->id)->sum('size') / 1000;
}); });

View File

@ -522,7 +522,7 @@ class DirectMessageController extends Controller
$hidden = false; $hidden = false;
} }
if(config('pixelfed.enforce_account_limit') == true) { if(config_cache('pixelfed.enforce_account_limit') == true) {
$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) { $size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
return Media::whereUserId($user->id)->sum('size') / 1000; return Media::whereUserId($user->id)->sum('size') / 1000;
}); });

View File

@ -25,7 +25,7 @@ trait HomeSettings
$id = Auth::user()->profile->id; $id = Auth::user()->profile->id;
$storage = []; $storage = [];
$used = Media::whereProfileId($id)->sum('size'); $used = Media::whereProfileId($id)->sum('size');
$storage['limit'] = config('pixelfed.max_account_size') * 1024; $storage['limit'] = config_cache('pixelfed.max_account_size') * 1024;
$storage['used'] = $used; $storage['used'] = $used;
$storage['percentUsed'] = ceil($storage['used'] / $storage['limit'] * 100); $storage['percentUsed'] = ceil($storage['used'] / $storage['limit'] * 100);
$storage['limitPretty'] = PrettyNumber::size($storage['limit']); $storage['limitPretty'] = PrettyNumber::size($storage['limit']);

View File

@ -23,7 +23,7 @@ class Config {
'optimize_video' => config('pixelfed.optimize_video'), 'optimize_video' => config('pixelfed.optimize_video'),
'media_types' => config_cache('pixelfed.media_types'), 'media_types' => config_cache('pixelfed.media_types'),
'enforce_account_limit' => config('pixelfed.enforce_account_limit') 'enforce_account_limit' => config_cache('pixelfed.enforce_account_limit')
], ],
'activitypub' => [ 'activitypub' => [

View File

@ -2,99 +2,99 @@
@section('section') @section('section')
<div class="title"> <div class="title">
<h3 class="font-weight-bold">Account Settings</h3> <h3 class="font-weight-bold">Account Settings</h3>
</div> </div>
<hr> <hr>
<div class="form-group row"> <div class="form-group row">
<div class="col-sm-3"> <div class="col-sm-3">
<img src="{{Auth::user()->profile->avatarUrl()}}" width="38px" height="38px" class="rounded-circle float-right"> <img src="{{Auth::user()->profile->avatarUrl()}}" width="38px" height="38px" class="rounded-circle float-right">
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<p class="lead font-weight-bold mb-0">{{Auth::user()->username}}</p> <p class="lead font-weight-bold mb-0">{{Auth::user()->username}}</p>
<p class=""> <p class="">
<a href="#" class="font-weight-bold change-profile-photo" data-toggle="collapse" data-target="#avatarCollapse" aria-expanded="false" aria-controls="avatarCollapse">Change Profile Photo</a> <a href="#" class="font-weight-bold change-profile-photo" data-toggle="collapse" data-target="#avatarCollapse" aria-expanded="false" aria-controls="avatarCollapse">Change Profile Photo</a>
</p> </p>
<div class="collapse" id="avatarCollapse"> <div class="collapse" id="avatarCollapse">
<form method="post" action="/settings/avatar" enctype="multipart/form-data"> <form method="post" action="/settings/avatar" enctype="multipart/form-data">
@csrf @csrf
<div class="card card-body"> <div class="card card-body">
<div class="custom-file mb-1"> <div class="custom-file mb-1">
<input type="file" name="avatar" class="custom-file-input" id="avatarInput"> <input type="file" name="avatar" class="custom-file-input" id="avatarInput">
<label class="custom-file-label" for="avatarInput">Select a profile photo</label> <label class="custom-file-label" for="avatarInput">Select a profile photo</label>
</div> </div>
<p><span class="small font-weight-bold">Must be a jpeg or png. Max avatar size: <span id="maxAvatarSize"></span></span></p> <p><span class="small font-weight-bold">Must be a jpeg or png. Max avatar size: <span id="maxAvatarSize"></span></span></p>
<div id="previewAvatar"></div> <div id="previewAvatar"></div>
<p class="mb-0"><button type="submit" class="btn btn-primary px-4 py-0 font-weight-bold">Upload</button></p> <p class="mb-0"><button type="submit" class="btn btn-primary px-4 py-0 font-weight-bold">Upload</button></p>
</div> </div>
</form> </form>
</div> </div>
<p class=""> <p class="">
<a class="font-weight-bold text-muted delete-profile-photo" href="#">Delete Profile Photo</a> <a class="font-weight-bold text-muted delete-profile-photo" href="#">Delete Profile Photo</a>
</p> </p>
</div> </div>
</div> </div>
<form method="post"> <form method="post">
@csrf @csrf
<div class="form-group row"> <div class="form-group row">
<label for="name" class="col-sm-3 col-form-label font-weight-bold">Name</label> <label for="name" class="col-sm-3 col-form-label font-weight-bold">Name</label>
<div class="col-sm-9"> <div class="col-sm-9">
<input type="text" class="form-control" id="name" name="name" placeholder="Your Name" value="{{Auth::user()->profile->name}}" v-pre> <input type="text" class="form-control" id="name" name="name" placeholder="Your Name" value="{{Auth::user()->profile->name}}" v-pre>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="website" class="col-sm-3 col-form-label font-weight-bold">Website</label> <label for="website" class="col-sm-3 col-form-label font-weight-bold">Website</label>
<div class="col-sm-9"> <div class="col-sm-9">
<input type="text" class="form-control" id="website" name="website" placeholder="Website" value="{{Auth::user()->profile->website}}" v-pre> <input type="text" class="form-control" id="website" name="website" placeholder="Website" value="{{Auth::user()->profile->website}}" v-pre>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="bio" class="col-sm-3 col-form-label font-weight-bold">Bio</label> <label for="bio" class="col-sm-3 col-form-label font-weight-bold">Bio</label>
<div class="col-sm-9"> <div class="col-sm-9">
<textarea class="form-control" id="bio" name="bio" placeholder="Add a bio here" rows="2" data-max-length="{{config('pixelfed.max_bio_length')}}" v-pre>{{Auth::user()->profile->bio}}</textarea> <textarea class="form-control" id="bio" name="bio" placeholder="Add a bio here" rows="2" data-max-length="{{config('pixelfed.max_bio_length')}}" v-pre>{{Auth::user()->profile->bio}}</textarea>
<p class="form-text"> <p class="form-text">
<span class="bio-counter float-right small text-muted">0/{{config('pixelfed.max_bio_length')}}</span> <span class="bio-counter float-right small text-muted">0/{{config('pixelfed.max_bio_length')}}</span>
</p> </p>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="language" class="col-sm-3 col-form-label font-weight-bold">Language</label> <label for="language" class="col-sm-3 col-form-label font-weight-bold">Language</label>
<div class="col-sm-9"> <div class="col-sm-9">
<select class="form-control" name="language"> <select class="form-control" name="language">
@foreach(App\Util\Localization\Localization::languages() as $lang) @foreach(App\Util\Localization\Localization::languages() as $lang)
<option value="{{$lang}}" {{(Auth::user()->language ?? 'en') == $lang ? 'selected':''}}>{{locale_get_display_language($lang, 'en')}} - {{locale_get_display_language($lang, $lang)}}</option> <option value="{{$lang}}" {{(Auth::user()->language ?? 'en') == $lang ? 'selected':''}}>{{locale_get_display_language($lang, 'en')}} - {{locale_get_display_language($lang, $lang)}}</option>
@endforeach @endforeach
</select> </select>
</div> </div>
</div> </div>
@if(config('pixelfed.enforce_account_limit')) @if(config_cache('pixelfed.enforce_account_limit'))
<div class="pt-3"> <div class="pt-3">
<p class="font-weight-bold text-muted text-center">Storage Usage</p> <p class="font-weight-bold text-muted text-center">Storage Usage</p>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label class="col-sm-3 col-form-label font-weight-bold">Storage Used</label> <label class="col-sm-3 col-form-label font-weight-bold">Storage Used</label>
<div class="col-sm-9"> <div class="col-sm-9">
<div class="progress mt-2"> <div class="progress mt-2">
<div class="progress-bar" role="progressbar" style="width: {{$storage['percentUsed']}}%" aria-valuenow="{{$storage['percentUsed']}}" aria-valuemin="0" aria-valuemax="100"></div> <div class="progress-bar" role="progressbar" style="width: {{$storage['percentUsed']}}%" aria-valuenow="{{$storage['percentUsed']}}" aria-valuemin="0" aria-valuemax="100"></div>
</div> </div>
<div class="help-text"> <div class="help-text">
<span class="small text-muted"> <span class="small text-muted">
{{$storage['percentUsed']}}% used {{$storage['percentUsed']}}% used
</span> </span>
<span class="small text-muted float-right"> <span class="small text-muted float-right">
{{$storage['usedPretty']}} / {{$storage['limitPretty']}} {{$storage['usedPretty']}} / {{$storage['limitPretty']}}
</span> </span>
</div> </div>
</div> </div>
</div> </div>
@endif @endif
<hr> <hr>
<div class="form-group row"> <div class="form-group row">
<div class="col-12 text-right"> <div class="col-12 text-right">
<button type="submit" class="btn btn-primary font-weight-bold py-0 px-5">Submit</button> <button type="submit" class="btn btn-primary font-weight-bold py-0 px-5">Submit</button>
</div> </div>
</div> </div>
</form> </form>
@endsection @endsection
@ -102,72 +102,72 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
let el = $('#bio'); let el = $('#bio');
let len = el.val().length; let len = el.val().length;
let limit = el.data('max-length'); let limit = el.data('max-length');
if(len > 100) { if(len > 100) {
el.attr('rows', '4'); el.attr('rows', '4');
} }
let val = len + ' / ' + limit; let val = len + ' / ' + limit;
if(len > limit) { if(len > limit) {
let diff = len - limit; let diff = len - limit;
val = '<span class="text-danger">-' + diff + '</span> / ' + limit; val = '<span class="text-danger">-' + diff + '</span> / ' + limit;
} }
$('.bio-counter').html(val); $('.bio-counter').html(val);
$('#bio').on('change keyup paste', function(e) { $('#bio').on('change keyup paste', function(e) {
let el = $(this); let el = $(this);
let len = el.val().length; let len = el.val().length;
let limit = el.data('max-length'); let limit = el.data('max-length');
if(len > 100) { if(len > 100) {
el.attr('rows', '4'); el.attr('rows', '4');
} }
let val = len + ' / ' + limit; let val = len + ' / ' + limit;
if(len > limit) { if(len > limit) {
let diff = len - limit; let diff = len - limit;
val = '<span class="text-danger">-' + diff + '</span> / ' + limit; val = '<span class="text-danger">-' + diff + '</span> / ' + limit;
} }
$('.bio-counter').html(val); $('.bio-counter').html(val);
}); });
$(document).on('click', '.modal-close', function(e) { $(document).on('click', '.modal-close', function(e) {
swal.close(); swal.close();
}); });
$('#maxAvatarSize').text(filesize({{config('pixelfed.max_avatar_size') * 1024}}, {round: 0})); $('#maxAvatarSize').text(filesize({{config('pixelfed.max_avatar_size') * 1024}}, {round: 0}));
$('#avatarInput').on('change', function(e) { $('#avatarInput').on('change', function(e) {
var file = document.getElementById('avatarInput').files[0]; var file = document.getElementById('avatarInput').files[0];
var reader = new FileReader(); var reader = new FileReader();
reader.addEventListener("load", function() { reader.addEventListener("load", function() {
$('#previewAvatar').html('<img src="' + reader.result + '" class="rounded-circle box-shadow mb-3" width="100%" height="100%"/>'); $('#previewAvatar').html('<img src="' + reader.result + '" class="rounded-circle box-shadow mb-3" width="100%" height="100%"/>');
}, false); }, false);
if (file) { if (file) {
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
}); });
$('.delete-profile-photo').on('click', function(e) { $('.delete-profile-photo').on('click', function(e) {
e.preventDefault(); e.preventDefault();
if(window.confirm('Are you sure you want to delete your profile photo.') == false) { if(window.confirm('Are you sure you want to delete your profile photo.') == false) {
return; return;
} }
axios.delete('/settings/avatar').then(res => { axios.delete('/settings/avatar').then(res => {
window.location.href = window.location.href; window.location.href = window.location.href;
}).catch(err => { }).catch(err => {
swal('Error', 'An error occured, please try again later', 'error'); swal('Error', 'An error occured, please try again later', 'error');
}); });
}); });
}) })
</script> </script>